Telerik gridview : How to refresh grid view after Database change

不羁的心 提交于 2019-12-07 07:58:32

问题


I'm using radgridview in C# winform application to show data from database. I'm also altering database through ADO.Net. The problem is after I change the database, for example by deleting a row or adding a new row, changes do not appear in gridview.
I also want to mention that I have bound database to gridview through smart tags and when I tried to create a new dataset and assign it to radgridview1.datasource I got tons of errors.
Any suggestion on how can force radgridview to reload it's datasource ?


回答1:


When datasource get changes, to refresh datagrid use following code :

this.radGridViewName.MasterTemplate.Refresh(null); 

this line solved my problem :-)




回答2:


You can use simple soultion to refresh data in grid:

MyGrid.DataSource = null;
MyGrid.DataSource = updatedData;



回答3:


Well, I found the answer myself. Although it only works on dataGridView and doesn't work on dataListView.
To delete a record and commit changes to database :

radGridView1.CurrentRow.Delete();
this.yourTableAdapter.Update(yourDataSet);

On the other hand, if you have added new records and you want to reform the list :

this.yourTableAdapter.Fill(yourDataSet.yourTabel);

If you know how to do the same with dataListView, I'll be glad to hear.




回答4:


Here is a tutorial, explaining in a step by step manner how to bind the grid. Once it is bound, changes introduced to the underlying source will be automatically reflected and changed in RadGridView will be updated in the DataTable after you Update the TableAdapter.




回答5:


This solution is similar to Alexander's:

List<ClassOfDataRow> t = radGridView.ItemsSource as List<ClassOfDataRow>;
radGridView.ItemsSource = null;
radGridView.ItemsSource = t;

ClassOfDataRow is the class used to store one row of data in the grid and radGridView is the name of your RadGridView.




回答6:


The dataset has a clear function which can be called before new data is passed to the dataset :

Resultset.Clear();
DataAdapter.fill(Resultset);
Radgridview.datasource=Resultset;


来源:https://stackoverflow.com/questions/16606911/telerik-gridview-how-to-refresh-grid-view-after-database-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!