We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to get column index on click of column header

Hi,

Which event will give me the column index of the column when mouse button is clicked on column header.

Thanks

3 Replies

AD Administrator Syncfusion Team March 21, 2007 05:52 PM UTC

Hi,

You can handle the MouseDown event of the grid and call the PointToRowCol method to detect the RowIndex and ColIndex of the cell in a Grid. Here is a code snipet

void gridDataBoundGrid1_MouseDown(object sender, MouseEventArgs e)
{
int row, col;
GridDataBoundGrid grid = sender as GridDataBoundGrid;
if (grid.PointToRowCol(new Point(e.X,e.Y), out row, out col))
{
if (grid.Model[row,col].CellType == "ColumnHeaderCell")
{
MessageBox.Show(string.Format( "Column Header Index is {0}", col));
}
}
}

Best regards,
Haneef


RD Rohit Desai September 15, 2021 12:58 PM UTC

You have sample for this issue

i want to change color for selected column

is it possible 




AR Arulpriya Ramalingam Syncfusion Team September 16, 2021 12:12 PM UTC

Hi Rohit, 
 
Thank you for your interest in Syncfusion products. 
 
Yes, the BackColor for selected column can be updated using the CellClick event. Please make use of the below code example. 
 
Code example 
 
//Event subscription 
gridControl1.CellClick += GridControl1_CellClick; 
 
//Event customization. 
private void GridControl1_CellClick(object sender, GridCellClickEventArgs e) 
{ 
   if(e.RowIndex == 0) 
    { 
        gridControl1.ColStyles[e.ColIndex].BackColor = Color.Red; 
} 
} 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Arulpriya R. 


Loader.
Live Chat Icon For mobile
Up arrow icon