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

Set style to a row in gridGroupingControl

Hi, Can we set a style for the row based on the record value. I don''t want to set the style on any event. for(int i = 0; i < this.gridGroupingControl1.Table.Records.Count ; i ++) { Record r = this.gridGroupingControl1.Table.Records[i]; int assetId = Convert.ToInt32(r.GetValue("ASSET_ID")); if (assetId < 0) { //I want to set style for that row } } Thanks, Prathima

14 Replies

AD Administrator Syncfusion Team July 8, 2005 10:17 AM UTC

You can use conditional row formats. GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("ASSET_ID_Check"); fd.Expression = "[ASSET_ID] < 0"; fd.Appearance.AnyCell.BackColor = Color.Red; this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd);


PV Prathima Venkobachar July 11, 2005 09:39 AM UTC

Hi, Thanks for the reply. This is exactly my requirenment. I am able to distinguish b/wn asset_id < 0 and asset_id > 0. I am trying to set the style as, if asset_id < 0 then all the columns in that row are editable. If asset_id > 0 then only few columns are editable in that row. It is applying corectly for the asset_id >0. But this is not applying for the conditionalformatted rows. I have pasted the code snippets.This may help in analysing my problem. -------------------------------------------------------------------------------------------------------------- GridTableDescriptor tableDescriptor = this.gridGroupingControl.TableDescriptor; GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("ASSET_ID_Check"); fd.Expression = "[ASSET_ID] < 0"; fd.Appearance.AnyCell.BackColor = Color.Silver; tableDescriptor.ConditionalFormats.Add(fd); ExpressionFieldDescriptor fieldDescriptor = new ExpressionFieldDescriptor(DisplayName, DbName, Type); tableDescriptor.ExpressionFields.Add(fieldDescriptor); tableDescriptor.Columns.LoadDefault(); GridTableCellStyleInfo editableAssetStyle = new GridTableCellStyleInfo(); editableAssetStyle.BackColor = Color.White; editableAssetStyle.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; editableAssetStyle.ReadOnly = false; editableAssetStyle.Borders.All = new GridBorder( GridBorderStyle.None ); GridTableCellStyleInfo readOnlyAssetStyle = new GridTableCellStyleInfo(); readOnlyAssetStyle.BackColor = Color.LightCyan; readOnlyAssetStyle.CellType = "Static"; readOnlyAssetStyle.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; readOnlyAssetStyle.ReadOnly = true; readOnlyAssetStyle.AllowEnter = true; readOnlyAssetStyle.Enabled = true; readOnlyAssetStyle.Borders.All = new GridBorder( GridBorderStyle.None ); if ( ! Calculated ) { //Checking if it is a expression field GridColumnDescriptor colDescriptor = new GridColumnDescriptor( displayName , keyName, displayName ,readOnly ,colWidth); if (ColVal.IsReadOnly) { colDescriptor.Appearance.AnyRecordFieldCell = new GridTableCellStyleInfo(readOnlyAssetStyle); } else { colDescriptor.Appearance.AnyRecordFieldCell = new GridTableCellStyleInfo(editableAssetStyle); } //Adding all the visible columns to the grid this.gridGroupingControl.TableDescriptor.Columns[keyName] = colDescriptor; this.gridGroupingControl.TableDescriptor.VisibleColumns.Add(colDescriptor.Name); } //Adding Expression field to the Grid Visible column list and setting the style else { this.sfgAssetView.TableDescriptor.VisibleColumns.Add(displayName); GridStyleInfo style = tableDescriptor.Columns[displayName].Appearance.AnyRecordFieldCell; style.HorizontalAlignment = GridHorizontalAlignment.Right; style.Format = selectedColumn.FormatString; style.TextColor = Color.Blue; style.Borders.All = new GridBorder( GridBorderStyle.None ); tableDescriptor.Columns[displayName].Width = colWidth; } I want to apply style for the rows which satisfies GridConditionalFormatDescriptor as editable fields in that row. how can I do that..? Now what is happening is the above style is overriding whatever I try to set for ConditionExp...where should I do that..?


PV Prathima Venkobachar July 11, 2005 09:46 AM UTC

>Hi, > >Thanks for the reply. >This is exactly my requirenment. >I am able to distinguish b/wn asset_id < 0 and asset_id > 0. >I am trying to set the style as, if asset_id < 0 then all the columns in that row are editable. > >If asset_id > 0 then only few columns are editable in that row. >It is applying corectly for the asset_id >0. But this is not applying for the conditionalformatted rows. > > >I have pasted the code snippets.This may help in analysing my problem. >-------------------------------------------------------------------------------------------------------------- > >GridTableDescriptor tableDescriptor = this.gridGroupingControl.TableDescriptor; > > >GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("ASSET_ID_Check"); >fd.Expression = "[ASSET_ID] < 0"; >fd.Appearance.AnyCell.BackColor = Color.Silver; >tableDescriptor.ConditionalFormats.Add(fd); > > >ExpressionFieldDescriptor fieldDescriptor = new ExpressionFieldDescriptor(DisplayName, DbName, Type); >tableDescriptor.ExpressionFields.Add(fieldDescriptor); > > >tableDescriptor.Columns.LoadDefault(); > > >GridTableCellStyleInfo editableAssetStyle = new GridTableCellStyleInfo(); >editableAssetStyle.BackColor = Color.White; >editableAssetStyle.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; >editableAssetStyle.ReadOnly = false; >editableAssetStyle.Borders.All = new GridBorder( GridBorderStyle.None ); > >GridTableCellStyleInfo readOnlyAssetStyle = new GridTableCellStyleInfo(); >readOnlyAssetStyle.BackColor = Color.LightCyan; >readOnlyAssetStyle.CellType = "Static"; >readOnlyAssetStyle.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; >readOnlyAssetStyle.ReadOnly = true; >readOnlyAssetStyle.AllowEnter = true; >readOnlyAssetStyle.Enabled = true; >readOnlyAssetStyle.Borders.All = new GridBorder( GridBorderStyle.None ); > >if ( ! Calculated ) { //Checking if it is a expression field > > > >GridColumnDescriptor colDescriptor = new GridColumnDescriptor( > displayName , keyName, displayName ,readOnly ,colWidth); > > >if (ColVal.IsReadOnly) { > colDescriptor.Appearance.AnyRecordFieldCell = new GridTableCellStyleInfo(readOnlyAssetStyle); >} >else { > > colDescriptor.Appearance.AnyRecordFieldCell = new GridTableCellStyleInfo(editableAssetStyle); >} > >//Adding all the visible columns to the grid > >this.gridGroupingControl.TableDescriptor.Columns[keyName] = colDescriptor; >this.gridGroupingControl.TableDescriptor.VisibleColumns.Add(colDescriptor.Name); > >} >//Adding Expression field to the Grid Visible column list and setting the style >else { >this.sfgAssetView.TableDescriptor.VisibleColumns.Add(displayName); >GridStyleInfo style = tableDescriptor.Columns[displayName].Appearance.AnyRecordFieldCell; >style.HorizontalAlignment = GridHorizontalAlignment.Right; >style.Format = selectedColumn.FormatString; >style.TextColor = Color.Blue; >style.Borders.All = new GridBorder( GridBorderStyle.None ); >tableDescriptor.Columns[displayName].Width = colWidth; > >} GridTableCellStyleInfo editableRows = new GridTableCellStyleInfo(); editableRows.BackColor = Color.White; editableRows.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; editableRows.ReadOnly = false; editableRows.Borders.All = new GridBorder( GridBorderStyle.None ); fd.Appearance.AnyRecordFieldCell = editableRows; > >I want to apply style for the rows which satisfies GridConditionalFormatDescriptor as editable fields in that row. >how can I do that..? > >Now what is happening is the above style is overriding whatever I try to set for ConditionExp...where should I do that..? > > >


AD Administrator Syncfusion Team July 11, 2005 10:12 AM UTC

I think you will have to add two conditional formats, one for each condition you want to apply, "[ASSET_ID] < 0 and "[ASSET_ID] > 0. (As long as the conditions are mutually exclusive, this should work). GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("readonly"); fd.Expression = "[ASSET_ID] < 0"; fd.Appearance.AnyCell = readOnlyAssetStyle; this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); fd = new GridConditionalFormatDescriptor("editable"); fd.Expression = "[ASSET_ID] > 0"; fd.Appearance.AnyCell = editableAssetStyle; this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd);


PV Prathima Venkobachar July 11, 2005 10:40 AM UTC

When asset_id > 0 few columns are non editable based on the some condition. But when asset_id < 0 all the colums are editable. I am using two seperate styles already for asset_id > 0 to make only few columns editable. Does this works if I apply two conditional format...? Thanks, Prathima


AD Administrator Syncfusion Team July 11, 2005 11:00 AM UTC

As long as the conditions are mutually exclusive, this should work. Did you try it and it did not work?


PV Prathima Venkobachar July 11, 2005 11:51 AM UTC

I tried giving two conditional formats. One with Asset_id < 0 and Asset_id > 0. When I gave only two style i.e readonly and editable it worked fine. GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("ASSET_ID_Check"); fd.Expression = "[ASSET_ID] < 0"; fd.Appearance.AnyCell.BackColor = Color.Silver; tableDescriptor.ConditionalFormats.Add(fd); fd.Appearance.AnyCell = editableAssetStyle; GridConditionalFormatDescriptor fd1 = new GridConditionalFormatDescriptor("ASSET_ID_Check"); fd1.Expression = "[ASSET_ID] > 0"; fd1.Appearance.AnyCell.BackColor = Color.Silver; tableDescriptor.ConditionalFormats.Add(fd1); fd1.Appearance.AnyCell = readOnlyAssetStyle; But when asset_id > 0 , i want to make few columns non editable and few columns readonly, how can I do that..? when we apply conditionla formats , it is applying for all the columns... Thanks, Prathima


AD Administrator Syncfusion Team July 11, 2005 12:59 PM UTC

If you only want to conditionally set the format on a few columns in a record when ASSET_ID > 0, then you will have to use the QueryCellStyleInfo event. You will not be able to do this just setting properties.


PV Prathima Venkobachar July 12, 2005 06:57 AM UTC

Howm can I do that on QueryCellStyleInfo event..? Thanks, Prathima


AD Administrator Syncfusion Team July 12, 2005 08:44 AM UTC

//this event makes Col1 readonly when Col2 is checked
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
	if(e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell 
		|| e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell)
	{
		if(e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.MappingName == "Col1")
		{
			GridRecord rec = e.TableCellIdentity.DisplayElement.ParentRecord as GridRecord;
			if(rec != null && rec.GetValue("Col2") != null && (bool)rec.GetValue("Col2"))
			{
				e.Style.ReadOnly = true;
			}
		}
	}
}

Here is a sample using this code.

http://www.syncfusion.com/Support/user/uploads/GGC_CheckBox_726e6be1.zip

            


PV Prathima Venkobachar July 12, 2005 10:07 AM UTC

Thanks for the sample.I will look into it. Prathima


AD Administrator Syncfusion Team May 5, 2006 01:22 PM UTC

What is the formatting for a conditional format such as the following: ASSET_ID = "stringValue" >You can use conditional row formats. > > >GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("ASSET_ID_Check"); >fd.Expression = "[ASSET_ID] < 0"; >fd.Appearance.AnyCell.BackColor = Color.Red; >this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); >


AD Administrator Syncfusion Team May 6, 2006 09:54 PM UTC

Hi, For string comparison, you can use Expression like: [ASSET_ID] like ''stringValue'' Please refer this help link for more details: http://www.syncfusion.com/library/gridwindows/addingexpressionfields.html Best regards, Jay


AD Administrator Syncfusion Team May 7, 2006 12:23 AM UTC

The string should be in single quotes not double quotes. Thanks, Jay

Loader.
Live Chat Icon For mobile
Up arrow icon