Update grid when datasource changed

11 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. Ivan Petrov
    Admin
    Ivan Petrov avatar
    717 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 >>
  4. 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)>









  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 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.

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

    Posted 21 Jan 2015 in reply to Dess | Tech Support Engineer, Sr. 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!
  7. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 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.

     
  8. Deasun
    Deasun avatar
    32 posts
    Member since:
    May 2019

    Posted 24 Feb in reply to Dess | Tech Support Engineer, Sr. Link to this post

    i know this is old but quick ? on this rebinding:

    objGrid.DataSource = null;            
    objGrid.DataSource = dvResult;

    This should work correct?

    ON first doing this it works fine. But sometimes on the next or more times I get an error the object is gone.

     

  9. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 posts

    Posted 25 Feb Link to this post

    Hello, Deasun

    Following the provided information, I was unable to reproduce the issue you are facing. I have attached my sample project. Could you please specify the exact steps how to reproduce the problem?

    Alternatively, feel free to to submit a support ticket from your Telerik account where you can provide a sample project demonstrating the error message that you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance. Thank you in advance. 

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  10. Deasun
    Deasun avatar
    32 posts
    Member since:
    May 2019

    Posted 25 Feb in reply to Dess | Tech Support Engineer, Sr. Link to this post

    thanks for the reply.

    I decided to open a new forum post on this with some detailed info.

    https://www.telerik.com/forums/weird-error-with-grid

     

  11. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 posts

    Posted 27 Feb Link to this post

    Hello, Deasun,

    Your question has already been answered in the other thread ("Weird Error with grid?") you have opened on the same topic. Please, see our answer there for more information.
    We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

    Thank you for your understanding.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top