Name of Columns

Hi,
When I want to refer a column in the GridControl, for hidden it for example, I use this instruction:

MyGrid.Cols.Hidden[n] = true;

Where 'n' is an integer less than or equal to # of columns

VS Intellisense shows me that I can change the 'n' by the name of the column (string). Can anybody tell me where I can find the name of a column?

Thanks in advance.



1 Reply

AR Arulpriya Ramalingam Syncfusion Team December 7, 2017 10:39 AM UTC

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;   
    }   
}   
   
Sample link: GridControl_HideCols   
   
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   


Loader.
Up arrow icon