Hi German,
Thanks for contacting Syncfusion support.
In the GridControl, the name of columns will not be maintained in a collection and the style for each cell is done based on the index. So, the GridControl does not have the direct support to hide the column based on the column name. This can be achieved by using the QueryColWidth event. In that event, the size of the column can be set to be zero to hide the column by using the Size property based on conditions. Please refer to the below code,
Code example
|
//To add the columns name in a collection
for (int i = 1; i <= this.gridControl1.ColCount; i++)
{
columnsCollection.Add(gridControl1[0, i].CellValue.ToString());
}
//Event triggering
this.gridControl1.QueryColWidth += GridControl1_QueryColWidth;
//Event customization
private void GridControl1_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
string cellValue = this.gridControl1[0, e.Index].CellValue.ToString();
string colName = columnsCollection[3];
if(cellValue == colName)
{
//To hide the column
e.Size = 0;
e.Handled = true;
}
} |
Note
In GridGroupingControl, the columns will be maintained in the GridColumnDescriptor collection and the columns will be hidden by setting the width of the column to zero based on the column name. Please refer to below code,
Code example
|
//To hide the column based on column name
this.gridGroupingControl1.TableDescriptor.Columns["Name"].Width = 0; |
Regards,
Arulpriya