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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Change Font color on a databoundgrid cell.

Thread ID:

Created:

Updated:

Platform:

Replies:

6599 Aug 19,2003 02:36 PM UTC Aug 19,2003 07:55 PM UTC WinForms 3
loading
Tags: GridControl
Jonas
Asked On August 19, 2003 02:36 PM UTC

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\n R: " + e.RowIndex + " C: " + e.ColIndex); this.dataBoundGrid1[e.RowIndex, e.ColIndex].TextColor = Color.Red; } }

Administrator [Syncfusion]
Replied On August 19, 2003 03:45 PM UTC

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

Jonas
Replied On August 19, 2003 06:26 PM UTC

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

Administrator [Syncfusion]
Replied On August 19, 2003 07:55 PM UTC

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));
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;