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.
Unfortunately, activation email could not send to your email. Please try again.

Selecting a color for a cell in a GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

73897 May 23,2008 05:04 PM May 28,2008 09:14 AM Windows Forms 4
loading
Tags: GridControl
Daniel Santos de Carvalho
Asked On May 23, 2008 05:04 PM

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?


Jisha Joy [Syncfusion]
Replied On May 26, 2008 01:16 AM

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



Daniel Santos de Carvalho
Replied On May 26, 2008 02:42 PM

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!


Jisha Joy [Syncfusion]
Replied On May 27, 2008 01:23 AM



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


Daniel Santos de Carvalho
Replied On May 28, 2008 09:14 AM

Hi Jisha!

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


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.

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.

;