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

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)