i have a DataTable with some data and i bind it with my DataGridView with this code:
dataGridView1.DataSource = Measures.Table;
In separate thread i read data from connected device and insert that into my DataTable with this code:
DataRow row = table.NewRow();
row[ "Time" ] = dt;
foreach ( var kvp in measures )
row[ kvp.Key ] = kvp.Value;
table.Rows.Add( row );
On my Form I am able to change it's main control with a button. Both controls are UserControl, of which one consists the dataGridView1 DataGridView. When I add a row to my DataTable, my DataGridView does not update, until I switch to the other control, and move back to the one with DGV.
I have read some solutions on stack, which basically tell me that i should use BindingSource, but this code:
BindingSource source = new BindingSource();
source.DataSource = Measures.Table;
dataGridView1.DataSource = source;
does not work as well.
I don't know why this happens, because I have also created a simple app with just DGV and DataTable updated with Timer.Tick event and it works there. Anyone knows any reason why this DGV is not updating itself? It updates itself only when forced to redraw (with switching controls or just form resize)
Measures
is a singleton with which i handle both adding data to datatable, logging them to a file and some other stuff.Measures.Table
is just a dumb property{ get { return table } }
. Also, as I have wrote above, i only have to force redraw with anything (like resizing form) and DGV will show what is needed. – Soul Reaver