Format data in the expression field

Hi, 1.How can we format the data in the expression fileds added in the gridgroupingcontrol..? I want to restrict the value to 3 decimal place. 2.I am using this event. this.gridgroupingcontrol.SyncfusionGridControl.SourceListListChanged +=new TableListChangedEventHandler(gridgroupingControl_ListChangedEventHandler); I have a chkbox column. On this event I want to know whether this chkbox is chcked or not.. How can I do this..? Thanks, Prathima

8 Replies

AD Administrator Syncfusion Team June 14, 2005 08:28 AM UTC

1) You need to set the system type of the expression field when you create it, and also set the Format property on its style. ExpressionFieldDescriptor fd = new ExpressionFieldDescriptor("Cost", "[Price] * [Quantity]", typeof(double)); this.grid.TableDescriptor.ExpressionFields.Add(fd); GridStyleInfo style = this.grid.TableDescriptor.Columns["Cost"].Appearance.AnyRecordFieldCell;; style.BackColor = Color.LightGoldenrodYellow; style.CellType = "Static"; style.HorizontalAlignment = GridHorizontalAlignment.Right; style.Format ="#.000"; 2) You can try code like:
if(e.Table.CurrentRecord != null)
{
	Console.WriteLine(e.Table.CurrentRecord.GetValue("CheckBoxCol"));
}


PV Prathima Venkobachar June 14, 2005 10:33 AM UTC

Thnaks for the reply. It works fine. Prathima


CV Catinat Velmourougan June 14, 2005 01:56 PM UTC

hi I tried the same but it didnt work for negative values thanx catinat


AD Administrator Syncfusion Team June 14, 2005 02:12 PM UTC

It seems to work for me in this sample. http://www.syncfusion.com/Support/user/uploads/GGC_ExpressionCOl_994e6894.zip Can you modify the sample to show the problem?


CV Catinat Velmourougan June 21, 2005 12:14 PM UTC

hi I was able to format the negative values to 3 decimal places.Thanx. Now I have a new requirement , I want to change the color of display based on the value. For eg., If the expression field evaluates to a negative value it should be shown as red else it should be black. How to do it?


AD Administrator Syncfusion Team June 21, 2005 02:34 PM UTC

You can use the TableControlPrepareViewStyleInfo event to manage this.
private void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
{
	GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
	if(style != null && style.TableCellIdentity.Column != null
		&& style.TableCellIdentity.Column.Name == "Col2"
		&& (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
		|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell))
	{
		int val = (int) style.CellValue;
		if(val < 0)
			style.TextColor = Color.Red;
	}
}


CV Catinat Velmourougan June 28, 2005 05:30 AM UTC

hi 1. This one involves an evnt. I just want it to be called by a method thro code. 2.I had set style information for every fielddescriptor.Then based on the value I change the style of each and every cell.But still my fielddescriptor style information overrides the cellstyle info I have attached the code. temp_5905.zip


AD Administrator Syncfusion Team June 28, 2005 08:03 AM UTC

You will have to use an event like TableControlPrepareViewStyleInfo to do this in a GridGroupingControl. The reason is that there is no cell specific storage allocated in a GridGroupingControl. If you absolutely need to have cell specific storage (so you can set cell specific style properties), then you will need to use a GridControl. Now you can add cell specific storage to make it seem like you are just setting cell properties in a GridGroupingControl. But under the covers you still have to handle an event (QueryCellStyleInfo) to actually apply the styles when the certain cell is requested. Take a look at this sample. \Syncfusion\Essential Studio\3.2.1.0\Windows\Grid.Windows\Samples\Grouping\EmployeeViewXmlIO

Loader.
Up arrow icon