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

Access cell colors inside CurrentCellChanging handler?

I have a grid with a lot of repetitive cell values which clutter up the display. It's easy enough to handle PrepareViewStyleInfo and set the TextColor equal to the BackColor. But the user needs to be able to edit the values, so I'm trying to force the TextColor back to Black inside a CurrentCellChanging handler. Problem is, I have no idea how to get at the cell colors from there. Usually, they're only accessible, I think, from methods that supply a GridStyleInfo object.

1 Reply

AD Administrator Syncfusion Team August 12, 2003 12:59 AM

One comment is that if you 'set' the color in PrepareViewStyleInfo, this will step on any other setting you may do (unless it is done later than PrepareViewStyleInfo). So, I would suggest you set both the non-editing color and editing color in PrepareViewStyleInfo.
private void gridControl1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
	if(e.RowIndex > 0 && e.ColIndex > 0)
	{
		GridCurrentCell cc = this.gridControl1.CurrentCell;
		if(cc != null && cc.HasCurrentCellAt(e.RowIndex, e.ColIndex) && cc.IsEditing)
		{
			e.Style.TextColor = Color.Black;
		}
		else
		{
		        e.Style.TextColor = Color.Gray;
		}
	}
}
If you want the color in CurrentCellChanging, then you would normally use an indexer on the grid to get the style for the cell. You would use grid.CurrentCell.RowIndex and grid.CurrentCell.ColIndex to specifiy the indexes.

Loader.
Live Chat Icon For mobile
Up arrow icon