This is a migrated thread and some comments may be shown as answers.

Requery GridView Data

2 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 27 May 2016, 12:26 AM
I have a GridView that is bound to a IList of objects. When I add or delete items from the List I would like to reflect those changes in the GridView. I can rebind the grid by setting the DataSource to the updated IList, but I lose the filters, sorting, scroll position, and selected item. Is there a way to refresh the data without losing all the aforementioned items? I tried the Refresh() command but that did not seem to do anything. I recall in Telerik MVC there used to be a requery option, is there something similar in Winforms?

2 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 27 May 2016, 01:44 AM

Hmm, I was taking a closer look at the documentation. Is the only way to reflect List changes is by using Binding Lists with Objects implementing INotifyPropertyChanged along with OnPropertyChanged called on every set? Is this the only way to accomplish this?

Link: http://docs.telerik.com/devtools/winforms/gridview/populating-with-data/reflecting-custom-object-changes-in-rgv

 

0
Dimitar
Telerik team
answered on 27 May 2016, 08:29 AM
Hello Ryan,

Thank you for writing.

If you use BindingList with objects that implement INotifyPropertyChanged the grid will automatically reflect any changes.

If you only use BindingList the add/remove operations will be handled, changing a particular object from the list would not be reflected. In this case, you will need to refresh the grid like this:
radGridView1.MasterTemplate.Refresh();

If you want to use List you will need to rebind this grid when any change is made. Please note that you can convert List to BindingList: c# - Convert IList<T> to BindingList<T> - Stack Overflow.

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or