[CLOSED] GridPanel get Column in ColumnModel by ID
Hi,
is there some way instead of only using index
Code:
this.GridPanel1.ColumnModel.SetHidden(2, true);
to get the correct Column by ID (without looping) like
Code:
this.GridPanel1.ColumnModel.SetHidden("ColumnID", true);
this.GridPanel1.ColumnModel.Columns["ColumnID"].Hidden = true;
this.GridPanel1.ColumnModel.Columns[this.GridPanel1.ColumnModel.findColumnIndex("ColumnID")].Hidden = true;
if not, whats the best way of looping over the set of columns on runtime?
If i use this code:
Code:
foreach (var col in GridPanel1.ColumnModel.Columns)
{
if (col.ColumnID.Equals("ID_XYZ"))
{
I receive this Exception: Unable to cast object of type 'Ext.Net.CheckColumn' to type 'Ext.Net.Column'.
Kind regards.
Create a new method and get the index
I tried the above solutions but none worked.
I decided to right a method that gets the array index of the column in the grid and then use the standard SetHidden method.
Code:
//get the index of the column in the grid
var columnIndex = getColumnIndex("columnName", dataGrid);
//hide the column
this.dataGrid.ColumnModel.SetHidden(columnIndex, false);
private int getColumnIndex(string id, GridPanel grid)
{
int ctr = 0;
foreach (var col in grid.ColumnModel.Columns)
{
if (col.ColumnID.Equals(id))
{
return ctr;
}
ctr++;
}
return ctr;
}