Update grid when datasource changed

7 posts, 0 answers
  1. Craig Broadhead
    Craig Broadhead avatar
    23 posts
    Member since:
    Jul 2010

    Posted 14 Mar 2012 Link to this post

    Hi All,

    I am using a datatable as datasource for my telerik gridview

    Mygrd.Datasource=myDatatable

    Then I made some changes to myDatatable

    Now I need to update Mygrd, the following code doesn't seem to work
    Mygrd.TableElement.Update(GridUINotifyAction.BatchDataChanged)
    Mygrd.MasterTemplate.Refresh()
    Also tried parameter "GridUINotifyAction.RowsChanged"  Doesn't work either

    What do I need to do to update the grid ?

    Thanks

  2. Craig Broadhead
    Craig Broadhead avatar
    23 posts
    Member since:
    Jul 2010

    Posted 14 Mar 2012 Link to this post

    I can put more detail code on how I made change to myDatatable
    private sub TestFunc()
      
    dim dtTemp as datatable=myDatatable.clone
    for i as integer =0 to 10
      dim dr as datarow=dttemp.newrow
     dr.item(0)=i
      dttemp.rows.add (dr)

    next
    myDataTable=dttemp
      
    '--I need refresh grid here 
    '--What do i need to do?
    end s
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 19 Mar 2012 Link to this post

    Hello Craig,

    Thank you for writing.

    I am not exactly sure what you want to achieve. I would give you a few solutions for different cases. If none of them covers your case I would kindly ask you to provide a detailed explanation of your scenario so I can help you find the best approach in the situation.

    1. If what you want to do is to add new entries to the data table, you should directly add them in the existing data table and all changes will be reflected in the RadGridView automatically.
    2. Taking into account that DateTable.Clone() only copies the schema of the table, if you want to clear the records and add new ones you should use the Clear() method on the original data table and then fill it with the new data. Again all changes will be reflected in the RadGridView.
    3. If you want to keep the data in your original table and only show the new one in the grid you should set the new table as DataSource for the RadGridView, but since you set the new table to the original one I guess this is less probable.
    4. If you want to make all the addition away from the RadGridView so it would not update itself on every row added you can surround the addition of rows with a RadGridView.BeginUpdate() and RadGridView.EndUpdate() calls.

    I hope this will be useful for you. Should you have further questions, I would be glad to help.

    All the best,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  5. Sz
    Sz avatar
    5 posts
    Member since:
    Aug 2013

    Posted 19 Jan 2015 Link to this post

    Hi,

    I have the same problem, I cannot refresh the datasource with these methods:

     Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles ButtonX1.Click<br>        RadGridViewFW3.DataSource = <Object: List(Of GridViewCellInfo)><br>        RadGridViewFW3.Refresh()<br>        RadGridViewFW3.Update()<br>        RadGridViewFW1.MasterTemplate.Refresh()<br>        RadGridViewFW3.TableElement.Update(GridUINotifyAction.Reset)<br>        RadGridViewFW3.TableElement.Update(GridUINotifyAction.DataChanged)<br>    End Sub


    The only way that working, if I set Nothing first as DataSource:

            RadGridViewFW3.DataSource = Nothing<br>        RadGridViewFW3.DataSource = <Object: List(Of GridViewRowInfo)>









  6. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 21 Jan 2015 Link to this post

    Hello,

    Thank you for writing.

    RadGridView is capable of fetching bindable properties and data. However, one important issue must be noted: during the data binding process, the grid extracts the data from the data source, but for any later changes in the data source, RadGridView should be notified. Your bindable collection and business objects should follow some standards established in .NET in order to notify RadGridView about the changes. Please refer to our Reflecting Custom Object Changes in RGV help article which is quite useful on this topic.

    If you are still experiencing any further difficulties, it would be greatly appreciated if you open a support ticket providing a sample project reproducing the undesired behavior. Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Sz
    Sz avatar
    5 posts
    Member since:
    Aug 2013

    Posted 21 Jan 2015 in reply to Dess Link to this post

    Hello,

    Thank you for the answer, it helped me very lot! But some cases may occur, that I cannot add the INotifiyPropertyChanged interface to a class. In this case there are no way to manually tell the RadGridView, that the datasource changed, please refresh (reload) it?

    Thanks for reply!
  8. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 26 Jan 2015 Link to this post

    Hello,

    In case you do not implement the INotifiyPropertyChanged interface, the possible solution is either to rebind the RadGridView (setting its DataSource property to null and binding it to the collection that contains the updated items), or call the MasterTemplate.Refresh method.

    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready