Labelsoft
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't think Binding will take much time. I think, you need to check your stored procedure and other code.
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't use List, Use type dataset or datatable for data source.
ASKER
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.
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.
ASKER
It seems I have found the culprit. If I remove the setting RowHeadersWidthSizeMode = System.Windows.Forms.DataG ridViewRow HeadersWid thSizeMode .AutoSizeT oAllHeader s, then my DataGridView suddenly loads in less than a second. This is a huge improvement compared to the minutes it takes otherwise.
ASKER
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.
ASKER
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).