This will be a stupid question but I have a datagridview with a BindingSource as datasource.
The bindingSources.Datasource is a own BindingList with sort support. All this works.
But when a record will be inserted in the sorted list, then it will placed at the end of the datagridiview. After a refresh (example with the mouse click), the record will be placed on the right place.
So, I think that I forget something to implementat or call to ensure that the inserted record will be displayed directy on the right place of the datagridview.
Who can help me with a tip.
Thanks.
I have this working with the following code.
Please excuse the rough code – I’m just showing the key pieces, but I can provide a more complete example if you need.
I have a SortableBindingList _names which is bound to my DataGridView. Then on my form I have a button, with a new names added in the Click even handler. This is working fine to add the name kevin between joe and pete.
So the key thing is that I sort my dataGridView after adding to the list.
I could have also provided an IComparer in my .Sort() call – the default comparer is just comparing on .ToString()
Interestingly, in my example, the following also works, when inserting the item:
Simply inserting the item at the right place is enough to make the grid display the list sorted correctly. I’m using the same SortableBindingList as you, the one shown at MartinWilley.com.
Could your problem be that you are adding rather then inserting?