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

Highlight individual cell in a Windows Form grid

Hi,

I would like to highlight (border and back color of) an individual cell in a Windows form grid.

Typical opearations are:
1. Right click on a cell and select an option (of some predefined options) and that should hightlight the cell

2. Search operation- search through the grid cells, when a match is found, hightlight that cell.

Do you have any sample or a explaining way for this type of operation?

I am using Syncfusion 4.2.0.37

Thanks,
Dheeraj

4 Replies

AD Administrator Syncfusion Team November 14, 2006 07:06 AM UTC

Hi Dheeraj,

Issue 1: highlight the current cell

If you want to highlight the current cell, you can handle the PrepareViewSyleInfo event and set the style for the currentcell. Here is a code snippet,

private void gridControl1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if( cc.RowIndex == e.RowIndex && e.ColIndex == cc.ColIndex)
{
e.Style.BackColor = grid.AlphaBlendSelectionColor;
e.Style.Borders.All = new GridBorder(GridBorderStyle.Solid);
}
}

Issue 2:

Please refer to the below forum thread for find functionality in a Grid.
http://www.syncfusion.com/support/Forums/message.aspx?MessageID=45839

Best Regards,
Haneef


SA Sandeep November 17, 2006 12:29 PM UTC

Hi Haneef,
It works very well for the current cell. But now we want it in such a way that I will choose any cell programmatically (like after searching the cell by any calculation) and then highlight the cell. I tried with your logic but it won't work. If I deactivate the program and again come to that form then I can see it is highlighted. How I can highlight it.

Following steps I want to do.
1. I will click one button.
2. Button will give me rowindex and colindex after some process.
3 I will highlight that cell of colindex and rowindex.
(I tried this with your logic of using previewstyleinfo event. but it is not hightlighting , only I can see it highlighted if I go to any other form and come back to the form)

Thanks,
Sandeep


SA Sandeep November 21, 2006 11:13 AM UTC

Hi Haneef,

Please provide me the solution for the above query. Its urjent.

Thanks,
Sandeep


AD Administrator Syncfusion Team November 21, 2006 11:35 AM UTC

Hi Sandeep,

Our apologies for the delay in response.

Use the Model.Selections property to manages selected ranges in the grid. It allows you to add and remove selections, determines selection state of a specific cell.

//highlight the row
this.grid1.Model.Selections.Add(GridRangeInfo.Row(RowIndex));
//highlight the cell
this.grid1.Model.Selections.Add(GridRangeInfo.Cell(RowIndex,ColIndex);
//highlight the cell
this.grid1.Model.Selections.Add(GridRangeInfo.Col(CoIIndex));

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon