.NET General

Moderators: None (Apply to moderate this forum)
Number of threads: 749
Number of posts: 1301

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
DataGridView refresh problem Posted by surfswirl on 29 Apr 2009 at 8:38 AM
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.

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;
		
	}	


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 :)
Report
Re: DataGridView refresh problem Posted by Psightoplazm on 29 Apr 2009 at 2:53 PM
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`~
Report
Re: DataGridView refresh problem Posted by surfswirl on 29 Apr 2009 at 5:09 PM
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!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.