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 a Cell and repaint with other background color

Hello How can repaint a cell with other background color in this cell, in the method CurrentCellAcceptedChanges? Thank of your risponse Liliana

3 Replies

LF Liliana Faerman December 1, 2004 02:38 PM UTC

Sorry, i forgot, in DBDG

AD Administrator Syncfusion Team December 1, 2004 03:13 PM UTC

In a GridDataBoundGrid, in order to set cell specific backcolors, then you must handle the PrepareViewStyleInfo event and dynamically provide the color based on the e.RowIndex and e.ColIndex values passed in, and you have to keep providing this backcolor as long as you want to see it. See this KB. Here are two eventhandlers that I think does what you described for a single cell.
private int colorRow = -2;
private int colorCol = -2;
private void gridDataBoundGrid1_CurrentCellAcceptedChanges(object sender, CancelEventArgs e)
	int tempRow = this.colorRow;
	int tempCol = this.colorCol;
	this.colorRow = -2;
	this.colorRow = -2;
	if(tempRow > -2)
		//repaint the old one so color goes away
		this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(tempRow, tempCol));
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	this.colorCol = cc.ColIndex;
	this.colorRow = cc.RowIndex;
	//paint the new one
	this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(this.colorRow, this.colorCol));
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
	if(e.ColIndex == this.colorCol && e.RowIndex == this.colorRow)
		e.Style.BackColor = Color.Red;

LF Liliana Faerman December 1, 2004 04:07 PM UTC

Thanks Clay. Regards!!

Live Chat Icon For mobile
Up arrow icon