• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2098
  • Last Modified:

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.
0
Labelsoft
Asked:
Labelsoft
3 Solutions
 
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
0
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now