Requery GridView Data

3 posts, 0 answers
  1. Ryan
    Ryan avatar
    9 posts
    Member since:
    Oct 2010

    Posted 26 May 2016 Link to this post

    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. Ryan
    Ryan avatar
    9 posts
    Member since:
    Oct 2010

    Posted 26 May 2016 Link to this post

    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?



  3. Dimitar
    Dimitar avatar
    1877 posts

    Posted 27 May 2016 Link to this post

    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:

    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.

    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.
Back to Top