Record rowState as Updated when row is updated in bound spread

Posted by: aslyon-getmail-no on 8 September 2017, 1:34 pm EST

  • Posted 8 September 2017, 1:34 pm EST


     I have a spread bound to a dataTable. My problem is that the rowState of a row is not set to Modified when I make changes in a cell, neither if I move to another cell. It seems I have to move to another row for the edited row to be marked Modified. I need to check this flag and I execute the following code:

    <FONT size=2>


    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> dt </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> DataTable

    dt= fpSampleData.DataSource


    <FONT color=#000000><FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    For</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Each</FONT></FONT><FONT size=2> aRow </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>In</FONT></FONT><FONT size=2> dt.Rows</FONT>

    <BLOCKQUOTE><FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    If</FONT></FONT><FONT size=2> aRow.RowState = DataRowState.Modified </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then</FONT></FONT><FONT size=2> </FONT>


    <FONT size=2><FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If

    </FONT></FONT></FONT></BLOCKQUOTE><FONT size=2><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Next</FONT></FONT><FONT size=2> aRow


    </FONT></FONT></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2><FONT color=#000000> This if statement doesn't seem to execute its code if I only make a change in one cell. I thought the above EndEdit code should fix this, but is there anything else smart that I have overlooked?</FONT></FONT></FONT>

    <FONT color=#0000ff size=2><FONT color=#0000ff size=2><FONT color=#000000>Anne</FONT>

  • Replied 8 September 2017, 1:34 pm EST


    The call to EndEdit on the DataRow is what is needed to mark the RowState correctly. Are you making sure to call the AcceptChanges method on the DataTable after binding to the Spread to mark all rows to UnChanged?

  • Replied 8 September 2017, 1:34 pm EST

    When I bind the datatable of course all rows are unChanged as I have just read the data from the database. The user makes his changes and selects a menu item which fires my function. Each time the function that looks for all the Modified rows, is called, I do an AcceptChanges after the loop has finished. But very often no rows have Modified flag set, even if the user has made a change in a cell, or if the user has changed several rows, all but the last one are flagged as Modified (which supports my supsicion that only when I change row si the Modified flag actually set). EndEdit seems to have no effect...?
  • Replied 8 September 2017, 1:34 pm EST


    Could you post a small zipped project reproducing this issue for us to debug. When you make a change in the Spread and cause the DataRow that is changed to have it's EndEdit called, then the RowState will change if there is no errors. You can get this EndEdit to be called by you programatically calling it or clicking off the row. You can check if any errors are causing this not to work by putting a break point in the Error and EditError events of the Spread.

    When you loop all the rows of the bound DataSource, what are the RowState's of each row? Have you checked them to see what they are set to?

  • Replied 8 September 2017, 1:34 pm EST


    thanks for your input. As I was trying to explain to you what was going on I figured out what was happening. My Spread is sorted ascending by 2 columns. If the sort order was the same as the row order in the bound DataTable everyting worked fine, but not if the Spread sorted the rows in a different order.

    Then I realized that the call to EndEdit, <FONT size=2>dt.Item(<FONT size=2>mySmplSheet.ActiveRowIndex</FONT>).EndEdit(), refers to the ActiveRow, 1, on the spread,</FONT><FONT size=2> while the same row has index 0 in the DataTable. Hence the wrong row in the DataTable got the EndEdit call. I guess there is no way of finding which row number in the DataTable that actually need to have EndEdit called when order of rows doesn't correspond?

    </FONT>So if I loop through my whole dataSource and call EndEdit for each and every row, then the RowState is updated the way it should.

    I understand you had your reasons to not support <FONT size=2>StopCellEditing anymore, but that command always seemed to do the trick...</FONT>

    <FONT size=2>Thanks anyway, I am grateful for Farpoint's fantastic support team!

    </FONT><FONT size=2></FONT>
  • Replied 8 September 2017, 1:34 pm EST


    We did use to update the bound DataSource on every cell change, but this became a large performance hit for customers making constant changes to cells in the Spread.We then decided to update on the row change, like the Grid controls that you can bind to the DataSource. To find the correct DataRow to call the EndEdit on, you can use the GetModelRowFromViewRow and GetDataRowFromModelRow methods of Spread to find where the edited row is.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels