473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Form drawing and painting very slow

Hi, I'm writing here because this issue is becoming more annoying with each day it passes.
So I have a form, a dataset with a few table adapters (3 to be precise) and a datagridview.The datagridview has a lot of columns as checkboxes (30 columns are checkboxes per row).
The problem is in the form drawing and painting, when first shown the form paints itself very slow and im running this on a relatively powerful computer (Pentium 2.4GHz with 2gb ram, running on windows xp). I can live with the slow painting on the first show, I can even make a loading screen (which is a lame solution cause it's a relatively simple form, but meh you cant have it all) but then even when it shows fully and the user starts working with it, adding some data , clicking on comoboxes, scrolling the data grid, everything paints very slow and reacts very slow, its like working on a computer which has its processor running on 100% usage, even dragging other windows across the form (like an explorer window) the windows that im dragging copies itself a few couple of times (leaves a trail behind it like when you don't have your video drivers installed).
I searched the net about this sort of issue, all i found is: put the form double buffered property to true and put the transparency color to none to fasten the drawing process, I've done that to little effect, there is some improvement when the double buffered property is true, but very little. The application is developed in Visual Studio 2008 professional edition. I've done little programming in previous versions of visual studio but don't think I had this sort of a problem, is this an issue of the 3.5 framework and is there any solution to this behavior.
Thanks on your kind help.
Sep 24 '08 #1
5 4222
weaknessforcats
9,208 Expert Mod 8TB
Is your computer in fact running at 100%

Second, it is your application that is doing that in Task Manager?

If so, start commenting out code until it speeds up. At some point you will find the culprit.

Usually, stuff like this is cause by multithreading where the threads are blocking each other rapidly so there is little forward progress. Are you using multiple threads?

Another thing to try is using a profiler to see where the time is spent.
Sep 24 '08 #2
1.Nope processor usage never goes to 100% and stays there except when executing the application and then when showing the form it briefly goes up to some 90% and then drops back down to idle(well firefox is known to keep it busy and vary on 2% to 4% ), but I think that's something to be expected
2.I'm not using multithreading, it's a simple application with a dataset created with the visual studio designer i've got 3 tables in it a simple many to many relational database, the form im refereeing to is the master/detail form, nothing big, nothing new.
3. I've also done some experimenting it seems that even if I don't use a datagridview but a simple form with textboxes binded to a table in a dataset with one tableadapter(all done with the lazy way of doing things that visual studio provides , drag and drop a table from the datasource list) i get the same problem or at least a portion of it, the form is drawn very slowly and other windows dragged over it replicate themselves.
4. I did try to remove some of the code prior to even posting here, and realized that if i remove all the controls on the form it will show instantaneously , but that is not a solution from obvious reasons, then i started putting back some of the controls and with a few textboxes it seems like it runs ok to some point (i still can see every text box been drawn on the first show of the form),but once i put the datagridview the issues are back there. But I don't think the issues is in the data grid itself, the data grid only worsens it, the other controls also make my form laggy, only not to that extent. I even tried disconnecting them (unbinding them from the bindingsources) and even with empty datagrid its been drawn slowly ( but not having data to draw, off course it's a bit faster).
5. When i scroll the datagridview task manager reports increase of cpu usage to about 80%, nothing strange there, is there?

Is your computer in fact running at 100%

Second, it is your application that is doing that in Task Manager?

If so, start commenting out code until it speeds up. At some point you will find the culprit.

Usually, stuff like this is cause by multithreading where the threads are blocking each other rapidly so there is little forward progress. Are you using multiple threads?

Another thing to try is using a profiler to see where the time is spent.
Sep 24 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
As your datagridview displays a checkbox, does it have to re-draw the entire griod up to that point?

I mean is there progrssion:
box 1 -> display box1
box 2 -> displays box 1 and box 2
box 3 -> display box 1, box2 and box 3

??
If so, do the re-displays require a re-query of your database for each box?

I don't know how the datagridview is implemented but I would be curious as to the process flow as each check box is displayed.

Have you put a display just ar your database query so you can see h9ow many queries were actually done? Maybe there is activity that you are not aware of.
Sep 24 '08 #4
As your datagridview displays a checkbox, does it have to re-draw the entire griod up to that point?

I mean is there progrssion:
box 1 -> display box1
box 2 -> displays box 1 and box 2
box 3 -> display box 1, box2 and box 3

??
If so, do the re-displays require a re-query of your database for each box?

I don't know how the datagridview is implemented but I would be curious as to the process flow as each check box is displayed.

Have you put a display just ar your database query so you can see h9ow many queries were actually done? Maybe there is activity that you are not aware of.
The DataGridView is bound to a bindingsource witch in turn gets the data from a table adapter which is filled with data from a "SELECT * FROM TABLE" query
Every checkbox in the datagrid represents a column in the table, there are 30 such columns in the table (bool columns) and therefor there are 30 such columns in the datagrid.Think of a table with 32 columns where 30 of them are Bool values the other 2 are int values (one of those is a primary key the other is a foreign key). The display requires only one query to the database and its done in the form load event. When I save the data i also do an insert command, and a select @@identity query just to get the ID of whats been inserted, and yes when I save the data I get the slow drawing of the checkboxes again, thats when it refreshes the data. But the problem exist when using the form aswell, like when scrolling through the datagridview when no query is been executed.
Sep 24 '08 #5
Meggan
4
I am having a related problem that might shed some light on yours. I have some code that sets the background color of a row depending on the status of the data in the row. At first I put this code in the DataBindingComplete event and it took a while for the form to load because each time I filtered the grid it ran through every row in the grid (visible or not) again to execute this code. So I moved the code to RowPrePaint. The form loaded quickly and it looked good until I scrolled down the grid to the bottom. When I got to last few rows the grid started flickering like it was painting each row again and again. Which is exactly what is happening even if I touch nothing and move nothing, the grid just keeps paint the rows. I am not sure why this is happening, but if you have code in one of the paint events, these events may be triggering more then you would expect causing your form load to slow down. (By the way, I tried to move the code to the cell formating event and that did not work well.)
Aug 5 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET...
21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
2
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am...
0
by: Rene | last post by:
I developed a "themed" application that relies heavily on background pictures for just about every control that the application uses, if the control does not have a background picture it is usually...
8
by: Benoit Martin | last post by:
I had to draw my own control because I couldn't find any control doing what I wanted it to do. This control has a grid that I need to have control over. To do that, I draw each line of the grid...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.