DataGridView takes very long to bind to datasource

Dear experts,

I have a winforms application that has a datagridview. I want to bind this datagridview to a bindinglist(of customobjects). The customobjects have 25 properties that need to be displayed in the datagridview. My problem is that if the bindinglist contains about 1000 customobjects it takes more than a minute before the binding is done.

Is there a way to speed up the binding process? It seems to me that it takes much longer than it should be. I already tried suspendlayout and resumelayout on the datagridview, but that did not help at all.
LVL 3
LabelsoftAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gdupadhyayCommented:
How you selecting properties from customobjects? are you using any filter criteria ?
If yes, did you try to filter the object by using LINQ?
0
LabelsoftAuthor Commented:
I am not using any filter criteria. I just populate the collection and bind it to the datagridview.

I also tried just adding the needed amount of rows to the datagridview and that also caused a serious delay (but not as much as with performing the databind).
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

gdupadhyayCommented:
I don't think Binding will take much time. I think, you need to check your stored procedure and other code.
0
LabelsoftAuthor Commented:
With debugging I have discovered that it is the DataGridView.DataSource = bindinglist(of customobjects) command that is taking so long to execute.
I tried adding empty rows to the DataGridView as well for every entry in the bindinglist(of customobjects) and that took some time as well. I am not really sure what is causing these operations to take so much time as it doesn't seem to me that it's really a large dataset at all.
0
CodeCruiserCommented:
This would be cumbersome but try looping through the list and populting a datatable object. Or if possible, load the datatable directly. Where is this list coming from?
0
gdupadhyayCommented:
Don't use List, Use type dataset or datatable for data source.
0
LabelsoftAuthor Commented:
The list comes from my business objects. On my form I have two DatagGridViews. In the first I display data that I read from an Excel sheet that the user provides. In the second sheet I display the data in a way that the user wants it to be saved into the database.
In both grids I will display the same amount of rows, but the strange thing is that my preview DataGridView is taking much longer to add rows to it than the one that displays all the rows from Excel (This is what happens when I do not databind and all the rows in code). Right now I have no idea what is causing this problem.
0
LabelsoftAuthor Commented:
It seems I have found the culprit. If I remove the setting RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders, then my DataGridView suddenly loads in less than a second. This is a huge improvement compared to the minutes it takes otherwise.
0
LabelsoftAuthor Commented:
While I found the solution myself, I would like to thank everyone for participating in the thread. I assigned everyone some points to thank you for your efforts made.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.