views:

56

answers:

1

HI, I've a DataGridView with this setting: d

dataGridView1.AllowUserToOrderColumns = true;

(so the users can reorder columns)

My problem is that I want to know the current order of columns. I've done this methond:

public List<int> getActualTaskOrder() {
            List<int> ris = new List<int>();
            int i=1;  
            while(i<this.dataGridView1.Columns.Count){
                DataGridViewColumn c= this.dataGridView1.Columns[i];

                if (c.Name != "**")
                {
                    Console.WriteLine(c.HeaderText);

                    ris.Insert(c.Index-1, System.Convert.ToInt32(c.Tag));
                }
                i++;
            }
            return ris;
        }

my problem is that the result (the order of columns) is always the same (also if I move columns in my gui)

+1  A: 

You need to look at the DisplayIndex of your columns; perhaps something like:

        var qry = from DataGridViewColumn col in grid.Columns
                  where col.Name != "**"
                  orderby col.DisplayIndex
                  select col.HeaderText;
        foreach (string txt in qry) {
            Console.WriteLine(txt);
        }
Marc Gravell