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:
Further research suggests I’m not the only one who came upon this weird behavior. See:
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: