Selecting a color for a cell in a GridDataBoundGrid

Hi,

I would like some help with a problem in my system. I created a personalize GridDataBoundGrid with the visual effects that i want to my system. I use this datagrid in many parts of the system, so everywhere in the system he has the same look. But after clicking in one of the cells of any grid, i want to change the color of the text of that specific cell dinamically after that was clicked.

Well i tried to change the "GridDataBoundGrid .Style.TextColor" in the click event, but it won't change. I used a "gridBaseStyle" to set the default color of the grids, but now, i don't now how to change a individual cell.

Can you help me to find a solution for this?


4 Replies

JJ Jisha Joy Syncfusion Team May 26, 2008 05:16 AM UTC

Hi Daniel,

This can be achieved by handling the PrepareViewStyleInfo event of GridDataBoundGrid. Please refer the code:



this.gridDataBoundGrid1.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(gridDataBoundGrid1_PrepareViewStyleInfo);


void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
if(this.gridDataBoundGrid1.CurrentCell.HasCurrentCellAt(e.RowIndex, e.ColIndex))
e.Style.TextColor = Color.Red;
}




Please refer the sample to illustrate this:

GDBGChangeColor.zip


Regrds,
Jisha




DS Daniel Santos de Carvalho May 26, 2008 06:42 PM UTC

Hi Jisha!

That is great, it is almost what i planned. But i wanted to change the color in a permanent way, after i click on the cell. Is there any way to use this event with the click event and a way to change the color of the cell that was clicked permanently?

Thanks a lot!



JJ Jisha Joy Syncfusion Team May 27, 2008 05:23 AM UTC



Hi Daniel,

Thank you for your update.

You need to handle the PrepareViewStyleInfo and Click event of GridDataBoundGrid.

Please refer the code:


ArrayList doubleClickedCells = new ArrayList();
void gridDataBoundGrid1_Click(object sender, EventArgs e)
{
int row, col;
Point pt = this.gridDataBoundGrid1.PointToClient(Cursor.Position);
if (this.gridDataBoundGrid1.PointToRowCol(pt, out row, out col))
{
int code = GetLookUpCode(row, col);
if (doubleClickedCells.IndexOf(code) == -1)
doubleClickedCells.Add(code);
else
doubleClickedCells.Remove(code);
this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(row, col), true);
}
}


private int GetLookUpCode(int row, int col)
{ return 10000 * col + row; }



void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{

if (doubleClickedCells.IndexOf(GetLookUpCode(e.RowIndex, e.ColIndex)) > -1)
{
e.Style.TextColor = Color.Blue;
}
}

Please refer the sample to illustrates this:

GDBGChangeColor.zip

Please let me know if this helps.

Regards,
Jisha



DS Daniel Santos de Carvalho May 28, 2008 01:14 PM UTC

Hi Jisha!

Thank you for you help, it worked perfectly! Thanks a lot!


Loader.
Up arrow icon