﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Changing the BO's editing state to new with values already filled.</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sat, 04 Jul 2026 18:06:29 GMT</lastBuildDate><ttl>20</ttl><item><title>Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6847.aspx</link><description>I have added a custom button on the [b]SF Maintenance form[/b] to copy the current row values of the business object. on the clicked event of the button(copy) what i am doing is &lt;br&gt;
1-&gt; Store the Current Row,&lt;br&gt;
2-&gt; Begin a new row for BO.&lt;br&gt;
3-&gt; fill the values by fetching from data row we have in 1-&gt; .&lt;br&gt;
4-&gt; invoke edit on the BO.&lt;br&gt;
&lt;br&gt;
here is the code.&lt;br&gt;
&lt;br&gt;
 DataRow currentRow = employeeBO1.CurrentRow;&lt;br&gt;
 employeeBO1.NewRow();&lt;br&gt;
 for (int i = 0; i &lt; currentRow.ItemArray.Length; i++)&lt;br&gt;
 {&lt;br&gt;
     employeeBO1.CurrentRow[i] = currentRow[i];&lt;br&gt;
 }&lt;br&gt;
 employeeBO1.Edit();&lt;br&gt;
&lt;br&gt;
Till this everything is working very fine but the problem occurs when i click save and there is any broken rules exists on the form. i got the message that There are 'X' broken rules present.&lt;br&gt;
when i click on the form to correct the values ...Zing...the new record gone..i reached to the last record that i copied. This works fine if there are no broken rules present for the new record....Please help...its very urgent..</description><pubDate>Mon, 19 Feb 2007 11:35:26 GMT</pubDate><dc:creator>Vikram Saxena</dc:creator></item><item><title>RE: Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6961.aspx</link><description>[quote]1-&gt; Store the Current Row,&lt;br&gt;
2-&gt; Begin a new row for BO.&lt;br&gt;
3-&gt; fill the values by fetching from data row we have in 1-&gt; .&lt;br&gt;
4-&gt; invoke edit on the BO.[/quote]&lt;br&gt;
&lt;br&gt;
To avoid the whole PK issue, I'd just change the logic a smidge:&lt;br&gt;
&lt;br&gt;
1. Store away the current row&lt;br&gt;
2. Invoke Add on BO&lt;br&gt;
3. Set all the data properties in the new row to those saved in step 1&lt;br&gt;
4. Invoke Save on BO.&lt;br&gt;
5. Invoke Edit on BO if you want user to edit the new copy.&lt;br&gt;
&lt;br&gt;
This way however the BO is managing the PK will be honored and you're UI will automatically be navigated to the new copy...if I understand the problem correctly. Hope this helps  :)</description><pubDate>Mon, 19 Feb 2007 11:35:26 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6870.aspx</link><description>You can do a foreach loop through the columns of the CurrentDataTable and if the columns are included in the PrimaryKeyFields array, then don't copy them.&amp;nbsp; &lt;/P&gt;&lt;P&gt;As for the problem with the row disappearing... there is a property called AutoNavigateToFirstBrokenRow; try setting it to false and see if that fixes your problem.</description><pubDate>Fri, 16 Feb 2007 09:05:55 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6869.aspx</link><description>It depends on the table row that is being copied.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;[codesnippet]Private Sub CopyRow(ByVal SourceBusinessObject As BusinessLayer, ByVal FieldsToSkip As System.Collections.Generic.List(Of String))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Establish Locals&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim loTemp As MyBO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim loColumn As DataColumn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Copy the data into the temp BO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; loTemp.CopyDataFrom(SourceBusinessObject, StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromDefaultView)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Set the index to the temp BO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; loTemp.SeekToPrimaryKey(SourceBusinessObject.MyPK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Create a new row in the source BO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SourceBusinessObject.NewRow()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Cycle through the columns&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each loColumn In SourceBusinessObject.CurrentDataTable.Columns&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Check for skipped fields&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If FieldsToSkip.Contains(loColumn.Columnname) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Continue For&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Copy the data&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SourceBusinessObject.CurrentRow.Item(loColumn.ColumnName) = loTemp.CurrentRow.Item(loColumn.ColumnName)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Clean Up&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; loTemp.Dispose()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;End Sub[/codesnippet]</description><pubDate>Fri, 16 Feb 2007 09:05:07 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6864.aspx</link><description>Hi,&lt;br&gt;
Can you provide any sample code to copy record?&lt;br&gt;
Any plan to add copy feature to SF.NET? As this is quite a common function and been asked many times in forum.&lt;br&gt;
&lt;br&gt;
Thank you</description><pubDate>Fri, 16 Feb 2007 08:35:35 GMT</pubDate><dc:creator>Chan</dc:creator></item><item><title>RE: Changing the BO's editing state to new with values already filled.</title><link>http://forum.strataframe.net/FindPost6857.aspx</link><description>Well, your code is kindof a dangerous copy :)&amp;nbsp; You are not taking into account any primary key fields, etc.&amp;nbsp; If your business object is managed your PKs or your database is auto-incrementing, then this is not going to work because the second row is the same as your first...including the PK which should be handed out.&lt;/P&gt;&lt;P&gt;You may need to take your PK and FK fields into account when copying.</description><pubDate>Fri, 16 Feb 2007 07:24:24 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>