Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Selected Row in DataGridView is not properly sorted

$
0
0
Hi,

I have a DataGridView where the user can modify Column1.  In turn it also updates Column2.  In order for Column2 to be updated immediately after Column1 is changed, I have an event handler for CurrentCellDirtyStateChanged event where the changes in Column1 are committed.

DataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);

The problem occurs when I try to sort.  Lets say I change Column1 in row 3, 5, and 7.  Then I click on Column 2 to sort.  I'm doing a programatic sort on Column2.  

DataGridView.Sort(Column2, ListSortDirection.Descending);

Row 7 was the last selected row.  Rows 3, and 5 are sorted properly.  Row 7 is sorted improperly.  If I select another row after  changing Row 7, then the sort works fine.  From first glance, it looks like the BindingSource that is attached  to the  DataGridView  is not being updated.  So, I looked ...several times...the  BindingSource does have the correct  updated information.  I've also checked the DataGridView and the  DataTable, they all have the appropriate row with the  updated information. 

Any input will be greatly appreciated.  :-)

Lida



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>