Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16462 |

    Hi,
    Is there a way I can have a fixed column at the right hand side of the grid – so the last column cannot be re-ordered?
    Thanks in advance.

    Imported from legacy forums. Posted by troy@querytool.com (had 618 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.