Telerik gridview: how to update grid view after changing database

I am using radgridview in a winform application for C # to display data from a database. I am also modifying the database through ADO.Net. The problem is that I am changing the database, for example, deleting a row or adding a new row, the changes are not displayed in the gridview.
I also want to mention that I linked the database to gridview via smart tags, and when I tried to create a new dataset and assigned it to radgridview1.datasource , I got a lot of errors.
Any suggestion on how to get radgridview reload its datasource ?

+4
source share
6 answers

Ok, I found the answer myself. Although it works only on dataGridView and does not work on dataListView .
To delete a record and make changes to the database:

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

On the other hand, if you added new entries and want to change the list:

 this.yourTableAdapter.Fill(yourDataSet.yourTabel); 

If you know how to do the same with dataListView , I will be happy to hear.

0
source

When the datasource receives the changes, use the following code to update the datagrid:

 this.radGridViewName.MasterTemplate.Refresh(null); 

this line solved my problem :-)

+4
source

You can use a simple soul to update data in a grid:

 MyGrid.DataSource = null; MyGrid.DataSource = updatedData; 
+1
source

Here is a tutorial explaining step by step how to tie a grid. Once it is bound, the changes made to the base source will be automatically reflected and changed in RadGridView, will be updated in the DataTable after updating the table adapter.

0
source

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.

0
source

A dataset has a clear function that can be called before new data is transferred to the dataset:

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

Source: https://habr.com/ru/post/1481356/


All Articles