1
votes

I have a list of objects and I want to rebind DataGridView in every second. I tried many things, bindingsource, BindingList with INotifyPropertyChanged interface . They work great when you have static collection in your code, but I need to update datasource from database so, in this way I have to iterate each object and check if it is new or deleted and update BindingList, but it is solution. I prefer writing like this in every second:

BindingListObeject = new BindingList<MyObject>(ListOfMyObjects);

or

BindingListObeject.Clear();
//in loop
BindingListObeject.Add(new_object);

DataGridView will have scrolling and also selected cell must be selected after rebinding datasource. And also grid should not flicker.

How can I manage that? I use EF to get my desired list of objects.

1
have you tried Suspend/ResumeLayout to avoid flickering? - McNets
Yes, I tried, still flickering - Alexander Mchedlishvili

1 Answers

1
votes

Try ObservableCollection() or any other collection with CollectionChange event

And don't ever do something like myCollection = ...anything... thats make new object with new handle for myCollection, awhile your grid still binded to older handle. Just change collection, do not renew it.