Home Forums WinForms controls Xceed Grid for WinForms Can I freeze Columns in v2?

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

    Simple question – can I freeze one (or multiple) columns from scrolling in the v2 version of the grid (i.e. without using code)?

    Thanks in advance!

    Imported from legacy forums. Posted by fgauer (had 2967 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t think you can, without using code. But here’s a class you can use to freeze the first column:<code>public class ColumnFreezer
    {
    private Xceed.Grid.Column column_;
    public ColumnFreezer(Xceed.Grid.Column column)
    {
    column_ = column;
    Xceed.Grid.GridControl grid = column.GridControl;
    if (grid != null) grid.FirstVisibleColumnChanged += new EventHandler(grid_FirstVisibleColumnChanged);
    }

    private void grid_FirstVisibleColumnChanged(object sender, EventArgs e)
    {
    Xceed.Grid.Column firstColumn = grid.FirstVisibleColumn;
    if (firstColumn != null && firstColumn != column_)
    column_.VisibleIndex = firstColumn.VisibleIndex;
    }
    }</code>
    To use it:<code>// after initializing the grid
    new ColumnFreezer(myGrid.Columns[“myColumn”]);</code>

    Imported from legacy forums. Posted by Tommy (had 267 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy – yes we already use a variation on that code to freeze a single column. Trouble is we get requests from end users that ask us to freeze multiple columns. It’s a small thing for us (developers) a BIG thing for our ends users…

    (…anyone from Xceed have a word on this? Seems like a reasonable request)

    Imported from legacy forums. Posted by fgauer (had 404 views)

    User (Old forums)
    Member
    Post count: 23064

    Freezing multiple columns? Haven’t tried it before, but I don’t think it’s that much different. Try this (untested code):<code>public class ColumnFreezer
    {
    private Xceed.Grid.Column[] columns_;
    public ColumnFreezer(params Xceed.Grid.Column[] columns)
    {
    columns_ = columns;
    if (columns != null && columns.Length > 0)
    {
    Xceed.Grid.GridControl grid = columns[0].GridControl;
    if (grid != null) grid.FirstVisibleColumnChanged += new EventHandler(grid_FirstVisibleColumnChanged);
    }
    }

    private void grid_FirstVisibleColumnChanged(object sender, EventArgs e)
    {
    Xceed.Grid.Column firstColumn = grid.FirstVisibleColumn;
    if (firstColumn != null && firstColumn != columns_[0])
    {
    int firstIndex = firstColumn.VisibleIndex;
    for(int i=0; i<columns_.Length; i++)
    columns_[i].VisibleIndex = firstIndex + i;
    }
    }
    }</code>Using it:<code>new ColumnFreezer(myGrid.Columns[“myColumn”]);
    new ColumnFreezer(myGrid.Columns[“myColumn1”], myGrid.Columns[“myColumn2”]);
    new ColumnFreezer(myGrid.Columns[“myColumn1”], myGrid.Columns[“myColumn2”], myGrid.Columns[“myColumn3”]);</code>
    If you try this, could you let me know if it works?

    Imported from legacy forums. Posted by Tommy (had 4279 views)

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