C
Chris Shepherd
Hello,
I have a DataGridView which binds to a DataSet. This DataSet is
populated by a third party utility, and will contain a number of columns
I don't need to display, but some that I do. These columns, for some odd
reason are never in a reliable order (ie: one time I get the data, the
"description" field in table 0 could be at position 15, another at 27,
and so on).
Here's the basic flow:
- Retrieve DataSet through third party utility.
- Assign a clone of the DataSet's table as the datasource for the grid.*
- Loop through columns in the grid and set them all as not visible.
- Apply formatting, and visibility only to those columns I want on the grid.
- Add the real DataSet's table as the datasource for the grid.*
- Apply DisplayIndexing.**
*Note: I do this because I discovered it's quite a bit faster to clone
the dataset, setup default formatting, and then reassign the data than
it is to simply assign the data and apply formatting to it. Something to
do with this being a large dataset (10000+ rows) I imagine.
Now, the problem I'm having is that even after reapplying the
DisplayIndexes to the columns, there are still 1-2 rogue columns. I've
trapped various events and shoved debugging messages everywhere to try
and see what could be causing this lack of order, but to no avail.
Essentially at all points in the process the DisplayIndex is not
actually being applied as I have indicated. To give an example:
dgv = my DataGridView.
dgv.Columns["column1"].DisplayIndex = 0;
dgv.Columns["column2"].DisplayIndex = 1;
dgv.Columns["column5"].DisplayIndex = 2;
dgv.Columns["column17"].DisplayIndex = 3;
dgv.Columns["column28"].DisplayIndex = 4;
dgv.Columns["column4"].DisplayIndex = 5;
dgv.Refresh();
This will yield a row reading like:
column1, column2, column28, column5, column4, column17
I've done a bit of researching on DisplayIndex, but there isn't a lot
out there that I've been able to find, and the few examples I've found
are index keyed instead of name keyed, however I highly doubt that has
anything to do with this issue.
I'm hoping it's one of those stupidly simple obvious things that I'll
look silly for not noticing.
Thanks in advance for any responses,
Chris.
I have a DataGridView which binds to a DataSet. This DataSet is
populated by a third party utility, and will contain a number of columns
I don't need to display, but some that I do. These columns, for some odd
reason are never in a reliable order (ie: one time I get the data, the
"description" field in table 0 could be at position 15, another at 27,
and so on).
Here's the basic flow:
- Retrieve DataSet through third party utility.
- Assign a clone of the DataSet's table as the datasource for the grid.*
- Loop through columns in the grid and set them all as not visible.
- Apply formatting, and visibility only to those columns I want on the grid.
- Add the real DataSet's table as the datasource for the grid.*
- Apply DisplayIndexing.**
*Note: I do this because I discovered it's quite a bit faster to clone
the dataset, setup default formatting, and then reassign the data than
it is to simply assign the data and apply formatting to it. Something to
do with this being a large dataset (10000+ rows) I imagine.
Now, the problem I'm having is that even after reapplying the
DisplayIndexes to the columns, there are still 1-2 rogue columns. I've
trapped various events and shoved debugging messages everywhere to try
and see what could be causing this lack of order, but to no avail.
Essentially at all points in the process the DisplayIndex is not
actually being applied as I have indicated. To give an example:
dgv = my DataGridView.
dgv.Columns["column1"].DisplayIndex = 0;
dgv.Columns["column2"].DisplayIndex = 1;
dgv.Columns["column5"].DisplayIndex = 2;
dgv.Columns["column17"].DisplayIndex = 3;
dgv.Columns["column28"].DisplayIndex = 4;
dgv.Columns["column4"].DisplayIndex = 5;
dgv.Refresh();
This will yield a row reading like:
column1, column2, column28, column5, column4, column17
I've done a bit of researching on DisplayIndex, but there isn't a lot
out there that I've been able to find, and the few examples I've found
are index keyed instead of name keyed, however I highly doubt that has
anything to do with this issue.
I'm hoping it's one of those stupidly simple obvious things that I'll
look silly for not noticing.
Thanks in advance for any responses,
Chris.