|
//Event Triggering
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
//Event customization
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
Record record = e.TableCellIdentity.DisplayElement.GetRecord();
if (e.TableCellIdentity.Column == null || record == null)
return;
if (record.Kind == DisplayElementKind.Record)
{
string description = record.GetValue("Description").ToString();
string sampleData = record.GetValue("SampleData").ToString();
if (e.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell
&& e.TableCellIdentity.Column.Name == "Phone" && description == "Desc10")
{
//To highlight the Phone column cells based on cell value of Description
e.Style.BackColor = Color.Green;
e.Style.TextColor = Color.White;
}
if (e.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell &&
e.TableCellIdentity.Column.Name == "CategoryName" && sampleData == "Data43")
{
//To highlight the CategoryName column cells based on cell value of sampleData
e.Style.BackColor = Color.HotPink;
e.Style.TextColor = Color.White;
}
}
} |
|
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
Record record = e.TableCellIdentity.DisplayElement.GetRecord();
if (e.TableCellIdentity.Column == null || record == null)
return;
if (record.Kind == DisplayElementKind.Record)
{
if (e.TableCellIdentity.Column.Name == "Description")
{
Int32 value = Convert.ToInt32(record.GetValue("Value"));
int fieldIndex = this.gridGroupingControl1.TableDescriptor.ColIndexToField(e.Style.CellIdentity.ColIndex);
Int32 oldValue = Convert.ToInt32(record.GetOldValue(e.Style.CellIdentity.ColIndex));
int cmp = CompareColumns.CompareNullableObjects(value, oldValue);
if (cmp > 0)
e.Style.BackColor = Color.Green;
else
e.Style.BackColor = Color.Red;
}
}
} |