Tag Archives: rowstate datarowview vb.net

DataRowView RowState Unchanged {2} After Changing Item Value

Came across a very perplexing .NET behavior as I was working with a databound ListBoxControl.

I have multiselect enabled (SelectionMode = Multiextended), and the task was to loop through all list items, insert a new item in database after the last selected item in listbox, and write the new order index back to the database as we loop.

I am using the tableadapter.Update() method and testing return value of 1 for successful update. For some reason it updates fine up until selected item in the listboxcontrol (talk about weird!), and upon further digging I found the RowState isn’t changed after setting the new order index value to my data field:

vb.net rowstate unchanged

Further research suggests I’m not the only one who came upon this weird behavior. See:

http://social.msdn.microsoft.com/Forums/windows/en-US/58bb75e2-4dd5-40cb-81d9-01ad04a4b8e8/datarowstate-not-updating-when-value-being-updated-via-binded-textbox?forum=winformsdatacontrols

The solution is to call EndEdit() method on the DataRowView to force RowState to Modified so the subsequent TableAdapter.Update() call will actually perform an update to the database:

vb.net rowstate modified after calling endedit