By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,548 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,548 IT Pros & Developers. It's quick & easy.

Form drawing and painting very slow

P: 5
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
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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

P: 5
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
Expert Mod 5K+
P: 9,197
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

P: 5
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

P: 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

Post your reply

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