Home Forums WinForms controls Xceed Grid for WinForms Column frieze Reply To: Column frieze

User (Old forums)
Member
Post count: 23064

There is no property you can set to do this.  However, you can always handle the VisibleIndexChanged event on each Column and do something like the following (assuming “Phone” is the last column and its VisibleIndex at startup is 2) :

private Dictionary<string, int > VisibleIndexDictionary;

private void Form1_Load( object sender, EventArgs e )

{

    VisibleIndexDictionary =

new Dictionary<string, int >( gridControl1.Columns.Count );

    foreach( Column col in gridControl1.Columns )

    {

        col.VisibleIndexChanged +=

new EventHandler( col_VisibleIndexChanged );

        VisibleIndexDictionary.Add( col.FieldName, col.VisibleIndex );

    }

}

void col_VisibleIndexChanged( object sender, EventArgs e )

{

    Column col = sender as Column;

    if( col != null )

    {

        if( col.FieldName != “Phone” && col.VisibleIndex == 2 )

        {

            col.VisibleIndexChanged -=

new EventHandler( col_VisibleIndexChanged );

            int index;

            VisibleIndexDictionary.TryGetValue( col.FieldName,

out index );

            col.VisibleIndex = index;

            col.VisibleIndexChanged +=

new EventHandler( col_VisibleIndexChanged );

        }

        else if( col.FieldName == “Phone” && col.VisibleIndex != 2 )

        {

            col.VisibleIndexChanged -=

new EventHandler( col_VisibleIndexChanged );

            col.VisibleIndex = 2;

            col.VisibleIndexChanged +=

new EventHandler( col_VisibleIndexChanged );

        }

        VisibleIndexDictionary[ col.FieldName ] = col.VisibleIndex;

    }

}

Imported from legacy forums. Posted by André (had 866 views)