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

Record Cell and Style

Hi, I have a record from a GridGroupingControl. How can I get access to a cell within this record and change style of this single cell only ? Thanks

5 Replies

AD Administrator Syncfusion Team April 4, 2005 04:06 PM UTC

You can set the value of a single cell, but you cannot ''set'' arbitrary style properties on a single cell. The reason is that the only thing stored on a cell by cell basis is the cell value (which is stored in the underlying data). If you want to change a cell style on a cell by cell basis, then you have to use the QueryCellStyleInfo event. Here is some code that makes record cells in the first column red and readonly.
private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
	GridTableCellStyleInfo style = (GridTableCellStyleInfo) e.Style;
	if (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
		|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) 
	{
		GridColumnDescriptor column = style.TableCellIdentity.Column;
		if (column.TableDescriptor.Columns.IndexOf(column) == 0) 
		{
			e.Style.BackColor = Color.Red;
			e.Style.ReadOnly = true;
		}
	}
}


AD Administrator Syncfusion Team April 5, 2005 09:32 AM UTC

Ok, got it. I''m using PrepareViewStyleInfo-Event. The following code works if I change a cell in the parent grid. What would i have to do differently if i would like to color a cell in the childtable ? In what way would i have to change the 2 if statements that the child table is searched and a cell in that childtable gets colored ? See code for coloring a cell in the parenttable. if (column.TableDescriptor.Columns.IndexOf(column) == m_syncGrid.TableDescriptor.Columns.IndexOf(Constants.DataBase.col_ETVT_Custom)) { try { if (Convert.ToBoolean(m_syncGrid.TableModel[e.Inner.RowIndex, m_syncGrid.TableModel.NameToColIndex(Constants.DataBase.col_ETVTmanuell)].CellValue)) { e.Inner.Style.BackColor = Color.PaleGreen; } } catch {} }


AD Administrator Syncfusion Team April 5, 2005 10:26 AM UTC

Instead of m_syncGrid, you can try using e.TableControl.Table to get at similar proeprties. And this e.TableControl will reflect either parent or child tables depending upon where you are. But you may want to use the GridTableCellStyleInfoIdentity for the cell. This gives you access to many more properties depending upon what you need.
private void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
{
	GridTableCellStyleInfo tableCellStyle = e.Inner.Style as GridTableCellStyleInfo;//e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
	GridTableCellStyleInfoIdentity tableCellInfo = tableCellStyle.TableCellIdentity;

	if(tableCellInfo.Column != null && tableCellInfo.Column.MappingName == Constants.DataBase.col_ETVT_Custom)
	{
		if(tableCellInfo.TableCellType == GridTableCellType.AlternateRecordFieldCell 
			|| tableCellInfo.TableCellType == GridTableCellType.RecordFieldCell)
		{
			GridRecord rec = (tableCellInfo.DisplayElement as GridRecordRow).ParentRecord;
			bool b = (rec.GetValue(Constants.DataBase.col_ETVTmanuell) == DBNull.Value) ? false : Convert.ToBoolean(rec.GetValue(Constants.DataBase.col_ETVTmanuell));
			if(Convert.ToBoolean(b))
					e.Inner.Style.BackColor = Color.PaleGreen;
		}
	}
}


AD Administrator Syncfusion Team April 5, 2005 02:10 PM UTC

I can''t find the child rows inside of these events. Neither QueryCellStyleInfo nor PepareViewStyleInfo seem to fire when the child rows are rendered. I used your code and logged the row names. None the child rows were printed. What am i missing ?


AD Administrator Syncfusion Team April 5, 2005 03:50 PM UTC

Here is a little sample. It has a parent and child table. Each have a column named Name. If you type a 1 into the Name column in either the parent or child table, it will change the backcolor of the cell to pale green, and put the TableDescriptor name in the cell. http://www.syncfusion.com/Support/user/uploads/GGC_Sample_12c493aa.zip Our upcoming 3.2 release has another way to do set individual cell styles. The \Syncfusion\Essential Studio\3.2.0.0\Windows\Grid.Windows\Samples\Grouping\EmployeViewXmlIO illustrates this technique. You may want to check this out when that release is ready.

Loader.
Live Chat Icon For mobile
Up arrow icon