Friday, July 25, 2014

GridConditionalFormatDescriptor and QueryCellStyleInfo- how to format a row and a single cell in gridgroupingcontrol of Syncfusion?

GridConditionalFormatDescriptor only allow you to row formatting. 
Sample:
  GridConditionalFormatDescriptor gridConditionaReplaced = new GridConditionalFormatDescriptor();
            gridConditionaReplaced.Appearance.AnyRecordFieldCell.Font.Bold = true;
            gridConditionaReplaced.Appearance.AnyRecordFieldCell.TextColor = System.Drawing.Color.Brown;
            gridConditionaReplaced.Expression = "[ORDER_STATUS] =  'Replaced'";

            gridList.TableDescriptor.ConditionalFormats.Add(gridConditionaReplaced);

If you want to format any one cell, then you need to use QueryCellStyleInfo or PrepareViewStyleInfo event to achieve that. Below is the example that shows to change backcolor of a negative value cell and bracket for nagative value cell. Please refer to the below code in which QueryCellStyleInfo event is used to achieve your need.
Sample:
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
e.Style.Format = "{#,##}"; // You can set your own format
}
}
}
}

No comments:

Post a Comment