Datagridview not refreshing
-
Hello Everyone. I hope someone can help me with this problem. i have a datatable bound to a bindingsource, and i display its content through a datagridview in this way: bindingSource1.DataSource = dataTable1 dataGridView1.DataSource = bindingSource1 My problem is that when i update the data contained in the table through the bindingsource, my datagridview does not refresh and keeps displaying the old values. but the strangest thing is that if i manually sort the datagridview by clicking a column header, the datagrid refreshes and displays the updated values. this occurs only if i manually click on the headers, it does not work if i sort the grid in the code or if i call datagridview1.refresh() I desperately need the datagrid to update its values as i update the bindingsource, without clicking anything. how can i do that? Thanks in Advance, Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
-
Hello Everyone. I hope someone can help me with this problem. i have a datatable bound to a bindingsource, and i display its content through a datagridview in this way: bindingSource1.DataSource = dataTable1 dataGridView1.DataSource = bindingSource1 My problem is that when i update the data contained in the table through the bindingsource, my datagridview does not refresh and keeps displaying the old values. but the strangest thing is that if i manually sort the datagridview by clicking a column header, the datagrid refreshes and displays the updated values. this occurs only if i manually click on the headers, it does not work if i sort the grid in the code or if i call datagridview1.refresh() I desperately need the datagrid to update its values as i update the bindingsource, without clicking anything. how can i do that? Thanks in Advance, Rey9999
~~~ From Milano to The Hague, easy as it goes ~~~
-
Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.
Sebrell wrote:
Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.
i tried but i still have the same problem...
~~~ From Milano to The Hague, easy as it goes ~~~
-
Sebrell wrote:
Have you tried calling Control.Invalidate(), then calling Control.Update() ? The sequence of these two method calls should force the DataGridView to redraw itself.
i tried but i still have the same problem...
~~~ From Milano to The Hague, easy as it goes ~~~
so much for the simple answer... I'm reminded of a similar problem I once had with a RichTextBox, where I needed to force it to redraw its scroll-bars. I solved that problem by writing a method along the lines of the following: (C# code, sorry) private void Jiggle() { if (this.Orientation == Orientation.Horizontal) { this.rtfBox.Width -= 3; this.rtfBox.Width += 3; } else { this.rtfBox.Height -= 3; this.rtfBox.Height += 3; } this.rtfBox.Invalidate(); } I then called this method from the method that needed to redraw the RichTextBox (which was a property setter for a container control). I was surprised how well it worked. Especially since the RichTextBox in question had its Dock property set to DockStyle.Fill. I'd suggest dynamically changing, by a small number of pixels (fewer than 8), the Width of one of the ColumnHeaders in your DataGridView, since it works when you click it. Or to change the Sort column to a different column, then back to the original column. HTH Sebrell -- modified at 14:30 Wednesday 18th October, 2006
-
so much for the simple answer... I'm reminded of a similar problem I once had with a RichTextBox, where I needed to force it to redraw its scroll-bars. I solved that problem by writing a method along the lines of the following: (C# code, sorry) private void Jiggle() { if (this.Orientation == Orientation.Horizontal) { this.rtfBox.Width -= 3; this.rtfBox.Width += 3; } else { this.rtfBox.Height -= 3; this.rtfBox.Height += 3; } this.rtfBox.Invalidate(); } I then called this method from the method that needed to redraw the RichTextBox (which was a property setter for a container control). I was surprised how well it worked. Especially since the RichTextBox in question had its Dock property set to DockStyle.Fill. I'd suggest dynamically changing, by a small number of pixels (fewer than 8), the Width of one of the ColumnHeaders in your DataGridView, since it works when you click it. Or to change the Sort column to a different column, then back to the original column. HTH Sebrell -- modified at 14:30 Wednesday 18th October, 2006