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

Change Font color on a databoundgrid cell.

I have a databound grid where I want to mouse over a cell and change it's color, and change it back when you mouse out. (just like an HTTP link) I used this.dataBoundGrid1[e.RowIndex, e.ColIndex].TextColor = Color.Red; For some reason it's not working. I guess I just did not call it right. Any suggestions? I coded something like this: private void dataBoundGrid1_CellMouseHover(object sender, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs e) { if(e.ColIndex == 1) { //MessageBox.Show("Here R: " + e.RowIndex + " C: " + e.ColIndex); this.dataBoundGrid1[e.RowIndex, e.ColIndex].TextColor = Color.Red; } }

3 Replies

AD Administrator Syncfusion Team August 19, 2003 10:45 AM

Jonas, In a GridDataBoundGrid, you cannot use indexers to set style properties (other than the Text) for individual cells.To control individual cell style properties in a GridDataBoundGrid, you can handle the PrepareViewStyleInfo event, and set the style properties there based on the e.RowIndex and e.ColIndex. So, if you want to set a color of a cell, you have to do it from PrepareViewStyleInfo (or Model.QueryCellInfo). Please look at the code snippet below which changes the color of a cell[1,2], and see if it helps you private void gridControl1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { if(e.RowIndex == 1 && e.ColIndex == 2) e.Style.BackColor = Color.Red; } Regards, Priti


JO Jonas August 19, 2003 01:26 PM

Hey Priti, I missworded my question. What I wanted to do was to have a set of text in a cell to change its color when you hover your mouse on that cell. Regards, Jonas Avellana


AD Administrator Syncfusion Team August 19, 2003 02:55 PM

I think you have to use PrepareViewStyleInfo to do something like this. In the event, test whether the mouse is over the cell being requested, and if so, color the text. To force the PrepareViewStyleInfo event to be fired when you need it, you can use the CellMouseHoverEnter and CellMouseHoverLeave events.
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0)
	{
		int row, col;
		Point pt = this.gridDataBoundGrid1.PointToClient(Control.MousePosition);
		if(this.gridDataBoundGrid1.PointToRowCol(pt, out row, out col, -1)
			&& row == e.RowIndex && col == e.ColIndex)
		{
			e.Style.TextColor = Color.Blue;
		}
	}
}

private void gridDataBoundGrid1_CellMouseHoverEnter(object sender, GridCellMouseEventArgs e)
{
	this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(e.RowIndex, e.ColIndex));
}

private void gridDataBoundGrid1_CellMouseHoverLeave(object sender, GridCellMouseEventArgs e)
{
	this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(e.RowIndex, e.ColIndex));
}

Loader.
Live Chat Icon For mobile
Up arrow icon