4

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 ?

Rsh
  • 7,214
  • 5
  • 36
  • 45
  • I don't think you can find anything special in code, After user presses delete button, I delete the row through ADO. that's all. – Rsh May 17 '13 at 10:45

6 Answers6

7

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

this.radGridViewName.MasterTemplate.Refresh(null); 

this line solved my problem :-)

giampaolo
  • 6,906
  • 5
  • 45
  • 73
Priyanka
  • 91
  • 1
  • 3
4

You can use simple soultion to refresh data in grid:

MyGrid.DataSource = null;
MyGrid.DataSource = updatedData;
alexmac
  • 19,087
  • 7
  • 58
  • 69
2

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.

Rsh
  • 7,214
  • 5
  • 36
  • 45
1

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.

checho
  • 3,092
  • 3
  • 18
  • 30
0

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

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;
wsduho
  • 377
  • 3
  • 9