DataGridView refresh problem

Hi, I encountered a problem with refreshing my Datagridview from a MySQL database.

Basically, my Datagridview is placed in a TabPage. This TabPage is toggled visually by a MenuStripItem. When the menu item is clicked, it will either open or close the TabPage. When it opens the TabPage, I have set an event handler to refresh the Datagridview with new data from the MySQL database.

These are the 2 event handlers for the MenuStripItem.

[code]private delegate void Update_Delegate(DataTable input);

private void db_list_update(DataTable input){
//db_list.DataSource = null;
db_list.EndEdit();
db_list.Refresh();
db_list.DataSource = input;
}

private void db_toggle(object sender, EventArgs e){
if (db_shown){
tab_control.TabPages.Remove(db_tab);
num_tabs_shown--;
check_tab_visibility();
db_shown = false;
//Hide_DB_List();
db_list.Invoke(new Update_Delegate(this.db_list_update), new object[] {db_test.mysql_query(db_query)});
}
else if (!db_shown){
tab_control.Visible = true;
tab_control.TabPages.Insert(0,db_tab);
tab_control.SelectedTab = db_tab;
num_tabs_shown++;
check_tab_visibility();
Show_DB_List();
db_list.Invoke(new Update_Delegate(this.db_list_update), new object[] {db_test.mysql_query(db_query)});
db_shown = true;
}
db_test = null;

} [/code]

The problem is that the data in the DataGridView refuses to be refreshed after the second click. That is, when I open the DataGridView, it loads from the database. Then I close it and it refreshes itself. When I open it again, it does not refresh thereafter.

Also, I have put in a HitTest to track the DataSource values of the DataGridView. The DataSource values are being updated but the DataGridView does not reflect the updated values from the DataSource despite my attempts to refresh it and reload the DataSource.

Any help will be much appreciated :)

Comments

  • for the life of me I can't reproduce this but have encountered it before. This is a painting issue. For some reason the refresh method will not tell all the cells to repaint themselves. I didn't have time to look into it before and can't figure out how to make it happen again, but if you call the select all method it will force all cells to repaint themselves. I believe what I did before was remembered the previous selection state so I could reset it after calling SelectAll

    That's a total hack and I'll keep my eye out for a better solution.

    Maybe this is a threading issue?


    ><//~Psightoplasm`~
  • Hi thanks for replying.

    However, as my code snipper indicates, I used the Control.Invoke/Control.BeginInvoke to handle the possibility of cross-thread calls. When I used Control.InvokeRequired to check if the call is cross-thread, the program turned up negative.

    Nevertheless, I will consider using the Select All call. Thanks!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories