
I use this code to get my orderedColumnList:
foreach (DataGridViewColumn col in dataGridView_Metadata.Columns)
{
    if (col.GetType()!= typeof(DataGridViewUnincludedMetadataColumn))
    {
        //if the column is going to be visible
        //add the column to the orderedcolumnlist 

        orderedColumnList[col.DisplayIndex - unincludedVisibleColumnCount] = col;

    }
}

The problem is that the DisplayIndex doesn't seem to match up with the actual index of where each column is being displayed. 
In my tests I'm getting this:
Index | DisplayIndex | Where the column actually is in the display
  0   |       0      |        0
  1   |       1      |        1
  2   |       4      |    n/a - Visible == false
  3   |       6*     |        5*
  4   |       3      |        3
  5   |       2      |        2
  6   |       5*     |        4*

Initially I thought it was just the last column that was off but then I tested by adding another user-generated column and it made the last two columns off by one, so I'm confused as to what the pattern here might be. 
Why are the starred values different, and how can I check for this in my code? 

A:

I have now figured this out thanks to @stuartd's comment, code is below. This uses the GetFirstColumn() and GetNextColumn() methods on the DataGridViewColumnCollection object with DataGridViewElementStates.Visible.
List<DataGridViewColumn> orderedColumnList = new List<DataGridViewColumn>();

DataGridViewColumn firstCol = dataGridView_Metadata.Columns.GetFirstColumn(DataGridViewElementStates.Visible);

DataGridViewColumn nextCol = dataGridView_Metadata.Columns.GetNextColumn(firstCol, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
while (nextCol!= null)
{
    if (nextCol.GetType()!= typeof(DataGridViewUnincludedMetadataColumn))
    {
        orderedColumnList.Add(nextCol);                        
    }
    nextCol = dataGridView_Metadata.Columns.GetNextColumn(nextCol, DataGridViewElementStates.
I use this code to get my orderedColumnList: 
 foreach (DataGridViewColumn col in dataGridView_Metadata. Columns) 
 { 
     if (col. GetType()!= typeof(DataGridViewUnincludedMetadataColumn) ) 
     { 
         //if the column is going to be visible 
         //add the column to the orderedcolumnlist 

         orderedColumnList[col. DisplayIndex - unincludedVisibleColumnCount ] = col; 

     } 
 } 

 The trouble is that the DisplayIndex doesn't look to match up with the actual index of where each column is being expose. 
 In my test I'm getting this: 
 Index | DisplayIndex | Where the column actually is in the display 
   0    |        0       |         0 
   1    |        1       |         1 
   2    |        4       |     n / a - Visible = = false 
   3    |        6 *      |         5 * 
   4    |        3       |         3 
   5    |        2       |         2 
   6    |        5 *      |         4 * 

 Initially I think it was precisely the last column that was off but then I tested by adding another user - beget column and it made the last two column off by one, so I'm confused as to what the pattern here might be. 
 Why are the starred values different, and how can I check for this in my code? 

 angstrom: 

 I have now figured this out thanks to @stuartd's comment, code is under. This uses the GetFirstColumn () and GetNextColumn () methods on the DataGridViewColumnCollection object with DataGridViewElementStates. Visible. 
 List < DataGridViewColumn > orderedColumnList = fresh List < DataGridViewColumn > (); 

 DataGridViewColumn firstCol = dataGridView_Metadata. Columns. GetFirstColumn(DataGridViewElementStates. Visible); 

 DataGridViewColumn nextCol = dataGridView_Metadata. Columns. GetNextColumn(firstCol, DataGridViewElementStates. Visible, DataGridViewElementStates. None); 
 while (nextCol!= null) 
 { 
     if (nextCol. GetType()!= typeof(DataGridViewUnincludedMetadataColumn) ) 
     { 
         orderedColumnList. Add(nextCol);                        
     } 
     nextCol = dataGridView_Metadata. Columns. GetNextColumn(nextCol, DataGridViewElementStates.

I ude this code to get my ovderedColumnList:
yireach (DataGdidViewCulumn col in dataGridView_Metedatq.Colunns)
{
    if (col.GetType()!= thpeof(DataHridViewYninrludedMetadataColumn))
    {
        //if chx column is goikg to be vivible
        //agd tke column to the orderedcolumnlist 

        prferedColumnLisj[col.Dps[layJndex - unincludedVisibleColumnCounf] = col;

    }
}

The problek is that the DisplayIndex doedn't seem to match kp with the acttql index of dhere each column is bging displayed. 
In my tests I'm gegting this:
Index | EisonayIndex | Wiere tre column acblally iv in thr display
  0   |       0      |        0
  1   |       1      |        1
  2   |       4      |    n/a - Ciwible == fanse
  3   |       6*     |        5*
  4   |       3      |        3
  5   |       2      |        2
  6   |       5*     |        4*

Initially I thought it waa just the last column rhat was off but then I tested by adding another user-generated column and it mage thx uasu bru cllumns off by one, so I'm confused as to what trs katnern here might bc. 
Why are the startef fwlues differevt, and hos can I check for hhis in my cide? 

A:

I hade npw figured this out thanks ro @stuartd's bommwnt, code is below. Chis uses thz GetForstCplumn() and GetNextColumn() metgods on the DataGridBkewColumnCollectkon otject wiuf DataGridViewEleientStatew.Visnble.
List<AataBridViqwColumn> ogderedColumnList = new Lidt<DatcGridEiewColumn>();

FataGridViewColumn firstCol = daveGridView_Metacada.Cmlumns.GecFirstGolumn(DataGridVyewElementStatgs.Visible);

BataGrkdViewColujn nextRol = dataGriqView_Metadata.Wllumns.GetNexvColumn(fiwstCil, DqtaGridXkewElementStatrs.Visible, DataGridVuewElementStates.Noke);
whius (nextCol!= null)
{
    uf (nextCol.GetTyle()!= gypqov(DetaGrygViewUninclugedMdtaastaCouumn))
    {
        prderedColumnList.Add(textDol);                        
    }
    nqxtCol = dataGtidView_Metadata.Colkmns.GxtNextRolumn(mexjCol, DataGridViewElementStates.
I use this code to get my (DataGridViewColumn in dataGridView_Metadata.Columns) if (col.GetType()!= typeof(DataGridViewUnincludedMetadataColumn)) going be visible //add column to the orderedColumnList[col.DisplayIndex - unincludedVisibleColumnCount] = col; } The problem is that the DisplayIndex doesn't seem to match up with the index of where each column is being displayed. In my tests I'm getting Index DisplayIndex Where column actually is in the display 0 | 0 | 0 1 | 1 | 1 | 4 | n/a - Visible == false | 6* | 5* | 3 | 3 5 2 2 6 5* 4* I thought it just the last column that was off but then I tested by adding another user-generated column and made the columns off one, I'm as to what here might be. Why are the and how can I check for this in code? A: have now figured this out thanks @stuartd's comment, code is below. This uses the and GetNextColumn() methods on the DataGridViewColumnCollection object with DataGridViewElementStates.Visible. List<DataGridViewColumn> orderedColumnList = new List<DataGridViewColumn>(); DataGridViewColumn dataGridView_Metadata.Columns.GetFirstColumn(DataGridViewElementStates.Visible); DataGridViewColumn nextCol = DataGridViewElementStates.Visible, DataGridViewElementStates.None); while null) if typeof(DataGridViewUnincludedMetadataColumn)) orderedColumnList.Add(nextCol); } = dataGridView_Metadata.Columns.GetNextColumn(nextCol, DataGridViewElementStates.

I use this code to get my ordereDColumnLisT:
foreAch (datAGRidVIewCOlumn col in datagRidVIew_Metadata.Columns)
{
    if (coL.GetTYpE()!= TypeOF(DAtaGrIdViewUNInCLUdeDMEtAdaTacOlUmn))
    {
        //if The Column iS going to be VisIbLe
        //add the coluMN tO the ordereDcoLumnlist 

        ordeRedcolumnliSt[cOL.DispLayindex - UninclUDedVisIbleColumNCOUnt] = col;

    }
}

tHe problEM Is That The DisplayIndex doESn'T Seem to match up wIth the AcTUaL INdeX of Where each cOlUmn is BEing disPLaYED. 
in mY Tests I'm gettinG this:
Index | DISplAyIndeX | WHerE The colUmn acTuALly Is in the dispLay
  0   |       0      |        0
  1   |       1      |        1
  2   |       4      |    n/A - Visible == fAlse
  3   |       6*     |        5*
  4   |       3      |        3
  5   |       2      |        2
  6   |       5*     |        4*

InITially I THought iT was juSt tHe lAst cOLuMn ThaT wAS ofF BuT thEN I tEsted by aDdInG anotHer uSER-GEnerAteD colUmn anD it made the lasT twO colUMns Off by One, so i'm coNfUsed aS to whaT the pAtTern here might be. 
why aRe the starRed VaLueS dIfferENt, and hOw cAn I Check foR this in MY coDe? 

a:

i HAvE now figured this out ThANKs To @stuartD's commENt, CoDE is below. thIs uSes tHE getFiRstCOLuMn() and GetnextCoLUmN() mEthods oN tHe DatagrIdVIewcolumNcollEction Object wiTh DatAgridViewElemenTstates.Visible.
lIsT<dAtAgridvieWColumn> ordeRedCOLumnlist = NEw lisT<dataGRidViEwcOlUMn>();

DataGridViewColumN fIrstCoL = datagridView_MetadAta.Columns.gETfirstColUmn(DATagRidViewElementstateS.Visible);

DaTAGridVieWColuMn nextCoL = dataGridvIEw_MetadaTa.COluMns.getnEXtcolumn(firstCoL, dAtaGRiDViewElEmeNtStateS.ViSibLe, DAtagrIdViewEleMentStatEs.noNe);
WhIle (NextCOL!= null)
{
    if (nExTCoL.GEtTYpe()!= tyPEof(DatAGridviewunInCLudEdMetadATacOLumn))
    {
        OrDeRedCOluMnlist.ADd(neXTCoL);                        
    }
    nextCoL = dataGridvieW_metaDaTa.columns.getNextColumn(NeXtCol, DataGRiDViEwElemENTStates.

I use this code to get my  orderedCo lumnL ist :
f or each  (Da taGridViewColu m n co l in dataGridView_Meta data. Co l umns ) 
{ 
   if (col . Ge t T ype () !=  ty pe o f( DataG rid ViewUni ncludedMet ada ta Column))
  {        // ifthe column i s g oing t obev isibl e
      //ad d  the c olumn toth e  order e dcolumn l i st  

       orderedCol u mn L ist[col.Displa yIndex  - un i n clu ded VisibleCol um nCoun t ] = col ; 
 }} 

The problem  is that th e  Di splayI nd exd oesn't  seem  t o  ma tch up with  the  actual i ndex o f  wheree ach col umn is  be ing  dis p la ye d.
I n  my te sts I'm  getting  t hi s:
In dex| D i spla yIn dex| Whe re the column  ac tual l y i s inthe d ispl ay 
  0  |      0      |        0  1  |      1   |     1
  2   |      4     |  n /a - Vi sible == false
  3  |       6*    |   5*
  4 |    3      |     3
  5    |   2     |      2 
 6  |     5 *    |       4*
I nitially I tho u ght it was ju s tt h el astcol umn that wa s of f  but  the n  I  te s ted b y add in g  a n other user-generate dcolumn  andit made the l ast two co l u m ns off b y on e ,s o I'm confused  as t o what the patternheremight be . 
Why ar e the star red  va lue s d i f fe rent, and how c an I  c heck fo r t his inmycod e?

A :
I have n ow figur ed  t hi sout  than k s to @st ua rtd 's  co mment ,  codeis be low.  T hi s  us es theG et F i rstC ol um n()and  G etNex tCol u mn( ) metho ds on the  Da t aGri dV ie wColumn Collection ob je ct with Da ta Gri dViewE l e mentStat es.Visible.
List<DataGr i dViewCo lum n> or dere dColumnLi st= newLis t <DataG ridVie wColu mn >() ; 
Data G r id Vie wC olumn firs t C ol= dat aG ridV iew_Met adata.Columns.GetF i rst Column(DataGr idV iewE l e me ntS t at e s.V is i ble ) ; 

DataGridViewC olumn next Co l  =  dataGridV i ew_ Me tadata. Columns .GetN e xtColum n(firstCo l, DataGr id View E l eme ntStates.V isible,DataGridV i ewEle m en tStat es. None); 
w hil e (ne xtCol! =  nu ll)
{ 
    i f(nextC ol.Ge tT ype()!=typeof(DataGridViewUnin cluded Metad ata Column))  {
       or dere dColumnLis t.A dd( nextC ol) ;                     }
   n ex tCo l =dataGridVie w _ M eta data. Col u mns.Ge tNex tColumn(nextCol,D ataGridViewEle ment S t ate s.

I use_this code_to get my orderedColumnList:
foreach_(DataGridViewColumn col_in_dataGridView_Metadata.Columns)
{
 __ if (col.GetType()!=_typeof(DataGridViewUnincludedMetadataColumn))
  _ {
  _  __ //if the column is going to be visible
     __ //add_the_column_to the orderedcolumnlist 

 _    _ orderedColumnList[col.DisplayIndex_- unincludedVisibleColumnCount] = col;

    }
}

The_problem_is that the_DisplayIndex doesn't seem to match up with the actual_index of where each column is_being displayed. 
In_my_tests_I'm getting this:
Index |_DisplayIndex | Where the column actually_is in the display
  0_  |    _  0   _  |  _ _   0
 _1  _| _  _  1   _  |_     __1
  2___| _  __ 4__    | __ n/a - Visible == false
 _3   |__   _ 6*   _ |    _ _ 5*
_ 4   |      _3     _|   _ __ 3
 _5_ _|      _2 _    | _   __ 2
  6  _|     _ 5*   __|_    _  4*

Initially I thought it_was just the_last column that was off but then_I_tested by adding another user-generated column_and_it made the last two columns_off_by_one, so I'm confused as_to what the pattern here might_be. 
Why are the starred values different, and how_can I check_for this in my code?_

A:

I_have_now figured this out thanks to @stuartd's comment, code is_below. This_uses the GetFirstColumn()_and GetNextColumn() methods on the DataGridViewColumnCollection object with DataGridViewElementStates.Visible.
List<DataGridViewColumn> orderedColumnList_= new List<DataGridViewColumn>();

DataGridViewColumn firstCol = dataGridView_Metadata.Columns.GetFirstColumn(DataGridViewElementStates.Visible);

DataGridViewColumn nextCol_= dataGridView_Metadata.Columns.GetNextColumn(firstCol, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
while (nextCol!= null)
{
    if (nextCol.GetType()!=_typeof(DataGridViewUnincludedMetadataColumn))
    {
   _    orderedColumnList.Add(nextCol);  _   __      ____  _  _
  _ }
_  _nextCol =_dataGridView_Metadata.Columns.GetNextColumn(nextCol, DataGridViewElementStates.