I am reordering the Columns in my DataGridView1. I a moving for example, Columns[3](which is the 4th position) into second position, in place of Columns[1].
So from
0123456789 - this is the normal order--------and it SHOULD become:
0312456789 - this is how it should be--------But after reorder:
0231456789 - how is finally reordering
I was happily saving and loading all this indexes-List and some Columns keep jumping around when I was loading the winapp. A couple of them were fine, they kept their original location after I move them, but one was just moving to the >>right by 1 index every time I reposition it (I reposition first and save and load and it jumped after was loaded). I hope is clear.
I chased and debug the code and I find out it is ONLY the datagrid reordering problem. Not my saving and loading. I made a TESTCODE and it clearly show that is indeed messing up the indexes. NOT all of them, but only specific ones. I am thinking 2 things:
1- my dataGridView1.Columns[i].DisplayIndex is not the right way of reading these indexes?
2- there are some settings I screw up when I was initially playing with datagridview. But... I looked as close as patiently as I could and every Columns (Collection) in DesignView is the same with each other. I check it 3 times and I cant see anything diferent from 1 to another. I know for sure I play around with 1 or 2 of them but definetly not all of them, so the rest are the default , and I compare everything (by looking) with the default ones. Maybe 1 super mischivious property is still not correct there?
I simply have no idea what it could be. I only know, it is messing up (very randomly) this datagridview Index. Very strange!
Maybe you have a clue what it can be?
So far this Datagridview component is doing a formidable job, I love it so far. Except some bumps on the road but it is a very good component.
Thank you again.
What I have tried:
List<int> ListCO = new List<int>();
private void dataGridView1_ColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
{
ListCO.Clear();
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
ListCO.Add(dataGridView1.Columns[i].DisplayIndex);
}
int debug = 0;
}
UPDATE !!!
I made a fresh new project and I remade this entire setup:
and the results are the same. So its not from my code.
https://i.imgur.com/pnq1Hc7.jpg[
^]
and
https://i.imgur.com/dt5WiJM.jpg[
^]
The steps are as following:
Add a new DataGridView component to your Form1
In DataGridView properties goto: Columns (Collections) and add 10 new Columns.
Select DataGridView component and from it's little top right arrow expandable menu, check "Enable Column Reordering".
Assign the event to it and paste my code and run it.
In run time, move column 4 into #2 place (so not the first but the second)
Now read my List order.