We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Computed Column in GridGroupingControl

I have a GridGroupingControl whose datasource contains three hierarchical tables, "Employees", "Orders", and "Details". In the Details table, there are columns for "Code" and "Units". I would like to add a new column at runtime, "Fee", which is computed from Code and Units by calling a function Adjust(Code, Units), which is just a simple C# method. Is it possible to do this in a GGC, or do I need to do the "Adjust" calcuation before the datasource is filled, i.e., in a stored procedure? Van Baker

7 Replies

AD Administrator Syncfusion Team August 29, 2005 06:43 PM UTC

There are a couple of ways to do this. The most straight-forward way is to add an unbound field to the grouping grid. In the QueryValue event handler, call your function that does the computation you want. Here is a KB on adding an unbound checkbox. You can add a Static cell for your computation in the same manner. But instead of getting the value from the hashtable as in the KB, you would call your function. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=293


VB vbaker August 29, 2005 09:51 PM UTC

Thanks, Clay. That works great. Only one slight problem is with formatting the new cell. Id like to force money-type formatting and using the following does not seem to work. (If the Fee is a whole number, the value is displayed without any decimal point): this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.AnyRecordFieldCell.Format = "##.00"; How should I do this? --Van Baker


AD Administrator Syncfusion Team August 29, 2005 11:31 PM UTC

For AnyRecordFieldCell.Format to work, AnyRecordFieldCell.CellValueType must also be set to something like typeof(double). Is this being done?


AD Administrator Syncfusion Team August 30, 2005 01:44 PM UTC

Yes, I am setting the type of the unbound column ("Fee") to double. Here is the code I am using: this.gridGroupingControl1.GetTableDescriptor("Details").UnboundFields.Add("Fee"); this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.AnyRecordFieldCell.CellValueType = typeof(double); this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.AnyRecordFieldCell.Format = "##.000"; For the unbound column, it''s like the format specification has no effect, whereas, for other columns in the same table it works fine. --Van Baker


AD Administrator Syncfusion Team August 30, 2005 02:45 PM UTC

Instead of this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.AnyRecordFieldCell.Format = "##.000"; try this: this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.RecordFieldCell.Format = "##.000"; this.gridGroupingControl1.GetTableDescriptor("Details").Columns["Fee"].Appearance.AlternateRecordFieldCell.Format = "##.000";


VB vbaker August 30, 2005 04:39 PM UTC

I tried that but it still does not work for me. I also tried specifying the CellValueType for the RecordFieldCell and AlternateRecordFieldCell. Still no joy. --Van Baker


AD Administrator Syncfusion Team August 30, 2005 05:38 PM UTC

It looks like to me the CellValueType is not getting propagated properly. As a work around until we get this addressed in our code, you can handle the TableControlDrawCellDisplayTest and explicitly format the cell there. Here is a little sample. http://www.syncfusion.com/Support/user/uploads/GGC_unboundCol_d2dbfd63.zip

Loader.
Live Chat Icon For mobile
Up arrow icon