|
-
Dec 20th, 2012, 06:11 AM
#1
Thread Starter
Addicted Member
[RESOLVED] DataGridView is too slow
Hello Everybody,
I have a DatagridView with 8 columns and about 150 rows. Now the thing is that I would rather prefer to display it as a hole (like an Excel sheet) than to have scroll bars. I will have more DGV on the same flowlayoutpanel and I wouldn't like to have as many scrollbars around.
So it's best to display the information as a single page.
The problem is that it is to slow and it doesn't have a smooth scrolling like an excel sheet. And another problem is: when I scroll the page if I want to select an item in the DGV the page jumps automatically up or down a few rows. Only the second time the selection is made correct.
Is there any way to improve or to optimize the DGV control for a better performance? Does the slowing have anything to do with the fact that I am reading from a database?
Thx.
-
Dec 20th, 2012, 07:53 AM
#2
Re: DataGridView is too slow
The better you explain the problem the more likely you will get responses, with that said.
Expain what you mean by a hole as in Excel, have never heard of a hole in Excel.
Describe how the DataGridView is loaded and if there are any events used. If possible supply code, make sure to wrap code in code blocks via the toolbar under Advance
-
Dec 20th, 2012, 08:24 AM
#3
Re: DataGridView is too slow
The display lags are most likely caused by your own code. Without knowing what you do with the DGV and how you do it, it's pointless to suggest anything.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Dec 20th, 2012, 08:51 AM
#4
Thread Starter
Addicted Member
Re: DataGridView is too slow
First of all, pardon my english. I wanted to say as a WHOLE (not hole
Now, the code is very simple. I have a database and a DGV with a binding source. The way I populate the DGV is like this:
Me.PieseDeExecutatTableAdapter.Fill(Me.ContacteDataSet.PieseDeExecutat)
where PieseDeExecutat is the name of my table.
The only changes that I have made is I hided two of the columns at runtime with:
dgvPieseDeExecutat.Columns("ID").Visible = False
dgvPieseDeExecutat.Columns("Stare").Visible = False
which are in the Paint Method of the DGV.
Also in the paint I have the code which is for dimensioning so it fits the whole screen on it's width. So, the columns width.
I get the screen width and then each column has a percentage of this value.
What I meant with excel is that no matter how many rows you have it still goes up and down very smooth.
That's it
-
Dec 20th, 2012, 09:16 AM
#5
Re: DataGridView is too slow
I would recommend moving your code from the paint event to directly after the DataGridView is loaded such as form load or in a button click event. There are standard events for the form such as Resize for working with what you have now rather than the paint event.
-
Dec 20th, 2012, 12:47 PM
#6
Re: DataGridView is too slow
Don't hide the columns using the Paint event... Better yet, don't hide any columns at all. You should manually add the columns to the datagridview (instead of letting it create the columns automatically). That way, you can specify which columns and in what order to display... You can do this either in the designer or in code. To do it in code:
Code:
DGV.AutoGenerateColumns = False
DGV.Columns.Add(New DataGridViewTextBoxColumn With {.HeaderText = "User ID", .DataPropertyName = "UserID"})
DGV.Columns.Add(New DataGridViewTextBoxColumn With {.HeaderText = "First Name", .DataPropertyName = "FName"})
DGV.Columns.Add(New DataGridViewTextBoxColumn With {.HeaderText = "Last Name", .DataPropertyName = "LName"})
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Dec 20th, 2012, 12:53 PM
#7
Lively Member
Re: DataGridView is too slow
It also depends on the type of database you are reading from. If you are using SQL and loading the DGV using data adapters, it is painfully slow. I recommend using SQL code to load then instead.
Some Ponies just want to watch the cereal burn.
-
Dec 20th, 2012, 02:18 PM
#8
Thread Starter
Addicted Member
Re: DataGridView is too slow
Ok. I will try doing all the changes and see what happens. Thank you all for your answers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|