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
?
Asked
Active
Viewed 2.7k times
4

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 Answers
7
When datasource get changes, to refresh datagrid use following code :
this.radGridViewName.MasterTemplate.Refresh(null);
this line solved my problem :-)
4
You can use simple soultion to refresh data in grid:
MyGrid.DataSource = null;
MyGrid.DataSource = updatedData;

alexmac
- 19,087
- 7
- 58
- 69
-
-
If I create a new dataset and fill it through `adapter.Fill(ds)` I get null pointer exception in `itemDatabound` event handler. – Rsh May 17 '13 at 11:04
-
As I said before, I didn't connect to db programmitically, I used smart tags properties. – Rsh May 17 '13 at 11:06
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
-
Well updating the TableAdapter is just what I suggested above :). Good luck. – checho Aug 27 '14 at 15:45
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