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.
Unfortunately, activation email could not send to your email. Please try again.

Set style to a row in gridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

31513 Jul 8,2005 05:44 AM May 6,2006 08:23 PM Windows Forms 14
loading
Tags: GridControl
Prathima Venkobachar
Asked On July 8, 2005 05:44 AM

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

Administrator [Syncfusion]
Replied On July 8, 2005 06:17 AM

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);

Prathima Venkobachar
Replied On July 11, 2005 05:39 AM

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..?

Prathima Venkobachar
Replied On July 11, 2005 05:46 AM

>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..? > > >

Administrator [Syncfusion]
Replied On July 11, 2005 06:12 AM

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);

Prathima Venkobachar
Replied On July 11, 2005 06:40 AM

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

Administrator [Syncfusion]
Replied On July 11, 2005 07:00 AM

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

Prathima Venkobachar
Replied On July 11, 2005 07:51 AM

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

Administrator [Syncfusion]
Replied On July 11, 2005 08:59 AM

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.

Prathima Venkobachar
Replied On July 12, 2005 02:57 AM

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

Administrator [Syncfusion]
Replied On July 12, 2005 04:44 AM

//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
 

Prathima Venkobachar
Replied On July 12, 2005 06:07 AM

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

Administrator [Syncfusion]
Replied On May 5, 2006 09:22 AM

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); >

Administrator [Syncfusion]
Replied On May 6, 2006 05:54 PM

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

Administrator [Syncfusion]
Replied On May 6, 2006 08:23 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;