grid.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(grid_QueryCellStyleInfo);
...... private void grid_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { decimal dMin = Convert.ToDecimal(decimal.MinValue); GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.Style; //Get style for selected cell GridTableCellType cellType = e.TableCellIdentity.TableCellType; //Get Cell type for selected cell object value = style.CellValue; //if cell is a record field if (cellType == GridTableCellType.RecordFieldCell || cellType == GridTableCellType.AlternateRecordFieldCell) { //If cell is a uint if (e.TableCellIdentity.Column.FieldDescriptor.FieldPropertyType == typeof(uint)) { //If cell value == min value then replace with a blank uint val = Convert.ToUInt32(value); if (val == uint.MinValue) value = 0;// "-"; }
//If cell is a decimal if (e.TableCellIdentity.Column.FieldDescriptor.FieldPropertyType == typeof(decimal)) { //If cell value == min value then replace with a blank decimal val = Convert.ToDecimal(value); if (val < 0) // == dMin) value = 0;// "-"; } }|
//Event Triggering
this.gridGroupingControl1.TableControlDrawCellDisplayText += GridGroupingControl1_TableControlDrawCellDisplayText;
//Event Customization
private void GridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
Object cellValue = e.Inner.Style.CellValue;
if (sty.TableCellIdentity.Column == null)
return;
if (sty.TableCellIdentity.Column.Name == "CategoryID" && sty.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell
&& Convert.ToInt16(cellValue) < 0)
{
e.Inner.DisplayText = "-";
}
} |