Home Forums WinForms controls Xceed Grid for WinForms Cell Backcolor Reply To: Cell Backcolor

User (Old forums)
Post count: 23064

You can do it, like this (the code below has not been tested):
1. Create a class that inherits from <b>Xceed.Grid.DataCell</b>:<code>public class MyDataCell : Xceed.Grid.DataCell
public MyDataCell() { }
public MyDataCell(string fieldName):base(fieldName) { }
public MyDataCell(MyDataCell template):base(template) { }
public MyDataCell(Column column):base(column) { }
protected override Cell CreateInstance() {
return new MyDataCell(this);
<b>protected override void PaintBackground(GridPaintEventArgs e) {
// here you put code to paint the background of the cell
}</code>2. Create a class that inherits from <b>Xceed.Grid.DataRow</b>:<code>public class MyDataRow : Xceed.Grid.DataRow
public MyDataRow() { }
public MyDataRow(MyDataRow template):base(template) { }
public MyDataRow(RowSelector selector):base(selector) { }
protected override Row CreateInstance() {
return new MyDataRow(this);
protected override Cell CreateCell(Column column) {
return new MyDataCell(column);
}</code>3. Set the <b>DataRowTemplate</b> property of your GridControl to an instance of your custom DataRow class:<code>grid.DataRowTemplate = new MyDataRow();</code>

Imported from legacy forums. Posted by Tommy (had 3979 views)