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

Update grid when datasource changed

10 Answers 2826 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Craig Broadhead
Top achievements
Rank 1
Craig Broadhead asked on 14 Mar 2012, 01:38 PM

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

10 Answers, 1 is accepted

Sort by
0
Craig Broadhead
Top achievements
Rank 1
answered on 14 Mar 2012, 02:35 PM
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
0
Ivan Petrov
Telerik team
answered on 19 Mar 2012, 09:58 AM
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 >>
0
Sz
Top achievements
Rank 1
answered on 19 Jan 2015, 11:41 AM
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)>









0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Jan 2015, 03:41 PM
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.

 
0
Sz
Top achievements
Rank 1
answered on 21 Jan 2015, 08:40 PM
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!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Jan 2015, 02:51 PM
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.

 
0
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
answered on 24 Feb 2020, 08:52 PM

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.

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2020, 01:29 PM
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.
0
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
answered on 25 Feb 2020, 01:32 PM

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

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Feb 2020, 03:20 PM
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.
Tags
GridView
Asked by
Craig Broadhead
Top achievements
Rank 1
Answers by
Craig Broadhead
Top achievements
Rank 1
Ivan Petrov
Telerik team
Sz
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Share this question
or