Update data view with updated data

I have a datagridview. I read the xml file and attached the data to the gridview. I modify the xml and save it in a different form. So I reread the xml file and bind it to the gridview. The data is getting updated values. But the grid does not update until closing and opens the application again. How to do it?

Thank.

Regards, Raghavendra

# 1

Is there a Databind () or Rebind () for a DataGridView? I installed the data source as follows:

dvMoviesList.DataSource = dtMovies;

If I add a new row to the dtMovies table and put the data source again, it will be reflected. But if I edit the values ​​of any of the existing rows and reassign the data source, it will not be reflected until I close and open the application again. Any ideas?

Thank.

+3
source share
5 answers

I think you need to place a BindingSource between a DataGridView and a DataTable.

DataGridView _dgv = new DataGridView();
BindingSource _bs = new BindingSource();
DataTable _dt = new DataTable();
.
.
.
_dgv.DataSource = _bs;
_bs.DataSource = _dt;

Now that it _dtis being updated, the BindingSource should take care of updating the DataGridView, and you need not worry about resetting any DataSource property. DataSource properties can be set in a method InitializeComponent()(constructor), form constructor, or Form.Load event handler.

+9
source

I am sure that I am going to suggest that this is not the right way, but I ran into the same problem and, as an ASP.NET developer, and didn’t work very much in winforms, the only solution I found was to set the data source to NULL. then reinstall the data.

: this.dataGridView.DataSource = null; this.dataGridView.DataSource = myDataSource;

, , Nasser, , , .

+1

?

dvMoviesList.Refresh();
0

, , .

ArrayList list = new ArrayList();
list = YourXMLContent.GetItems(); 
GridView1.datasource = list;  // you can use you DataTable instead of list
GridView1.update();
Gridview1.invalidate();

.

0

FYI: DataSource DataSet DataTable. DataSet , . DataTable DataSet .

By the way, I set the DataSource property in an intermediate BindingSource object that was associated with a DataGridView, and not in the DataGridView itself. Not sure if that matters.

This can only concern the question, since the DataSource in the question was XML, not a DataSet. However, others with my problem are likely to come across this topic (like me), so I posted it anyway.

0
source

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


All Articles