c# - Reordering columns in DataGridView -


i'm populating datagridview (winforms) through code , biding rows datatable. property reordering columns set true.
if reorder columns , want new order of columns order same. means if first columns named "id" , last columns named "price", moving id in place of price , price in place of id , if want list columns using piece of code:

            (int = 0; <= dganalyse.columns.count - 1; i++)             {                 if (dganalyse.columns[i].visible == true)                 {                     console.writeline(dganalyse.columns[i].headertext);                 }             } 

i get: id, price not price, id.

is possible list of new order of columns?

if reorder columns , want new order of columns order same.

when change order of columns @ runtime using datagridview.allowusertoordercolumns functionality, it won't change order of datagridview.columns collection. displayindex property of columns change.

if want iterate columns in display order, use link:

c#

var q = c in this.datagridview1.columns.cast<datagridviewcolumn>()orderby c.displayindex select c; foreach (datagridviewcolumn column in q)  {     if (column.visible == true)      {     console.writeline(column.headertext.tostring());     } } 

vb.net

dim q = c in me.datagridview1.columns.cast(of datagridviewcolumn)() order c.displayindex select c each column in q         if column.visible             console.writeline(column.headertext.tostring())         end if next 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -