How to hide edge case cases (minimum values) in a grid
I am using a GridGroupingControl to display a set of data which is updated in the backend in realtime.
However certain columns is populated with minimum values as null values are not allowed by the incoming data source.
As such if i see a value like that 'd like to 'hide' it or replace it with a minus(-) to indicate it is not relevant. (Either will work)
What i've done so far is to use a QueryCellStyleInfo event to check cell type and field type and then apply the changes to the cell value but it doesn't work as i'd thought.
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;// "-"; } }
SIGN IN To post a reply.
3 Replies
AR
Arulpriya Ramalingam
Syncfusion Team
December 12, 2017 12:23 PM UTC
Hi James,
Thanks for contacting Syncfusion support.
We could understand your requirement. In order to replace the display text of a cell based on condition, the TableControlDrawCellDisplayText event can be used. In that event, the DisplayText property can be used to set the custom string to the cell based on conditions. We have created a simple sample as per your requirement. Please make use of below code and sample,
Code example
|
//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 = "-";
}
} |
Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/DisplayText-2103440504
Regards,
Arulpriya
JR
James Roodt
December 12, 2017 01:13 PM UTC
Thank you. This is perfect.
I was playing around with the QueryCellText and didn't see the DrawCellDisplayText event.
Much appreciated!
AR
Arulpriya Ramalingam
Syncfusion Team
December 13, 2017 04:41 AM UTC
Hi James,
Thanks for your appreciation.
We are glad to hear that the provided solution was resolved your scenario.
Please let us know if you have any other queries.
Regards,
Arulpriya
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JR James Roodt
- Dec 11, 2017 10:05 AM UTC
- Dec 13, 2017 04:41 AM UTC