Custom Field Type Demo

This sample shows custom types in a record. Custom types can have UITypeEditor or TypeConverters. It also demonstrates how to show the nested properties of a custom type in a record row.

This is how the sample looks.

CustomFiledType

Two classes called Foo and NestedFoo are declared with two properties. A table is created with columns that are declared as Property classes. Two columns are created with the data type declared as Foo and NestedFoo.

    		DataTable table = new DataTable();
    		table.Columns.Add("FooColumn1", typeof(Foo));
    		table.Columns.Add("FooColumn2", typeof(NestedFoo));
    		table.Columns.Add("Boolean", typeof(bool));
    		table.Columns.Add("Color", typeof(Color));
    		table.Columns.Add("Font", typeof(Font));
    		table.Columns.Add("PatternStyle", typeof(Syncfusion.Drawing.PatternStyle));
    		table.Columns.Add("DockStyle", typeof(DockStyle));
    		table.Columns.Add("FieldDescriptor", typeof(FieldDescriptor));
    		table.Columns.Add("BordersInfo", typeof(GridBordersInfo));  

A column can be manually added through the following code:

    		gridGroupingControl1.TableDescriptor.Columns.Clear();
    		gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn1_PropertyOne");
    		gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn1_PropertyTwo"); 

An unbound column can be added as follows:

    		GridTableDescriptor td = this.gridGroupingControl1.TableDescriptor;
    		FieldDescriptor unboundFd = new FieldDescriptor("Unbound");
    		td.UnboundFields.Add(unboundFd);  

The UI's Type Editors feature can be implemented using the following code:

    		this.gridGroupingControl1.TableOptions.AllowDropDownCell = showUITypeEditors;  

The following code shows how to enable or disable the UI-type editor for the check-box column.

 
    		bool displayCheckBoxForBooleanFields = false;
    			if (displayCheckBoxForBooleanFields)
    			{
    				GridPropertyTypeDefaultStyle booleanDefault = this.gridGroupingControl1.Engine.PropertyTypeDefaultStyles["System.Boolean"];
    				booleanDefault.AllowDropDown = false;
    			}  

Here is the sample code to get the row and column index in the grid for a column (this works if column-sets with multiple rows are specified).


    		bool useOldCodeToGetCellInfo = false;
    		if (useOldCodeToGetCellInfo)
    		{
    			GridColumnDescriptor cd = this.gridGroupingControl1.TableDescriptor.Columns["Boolean"];
    			int relativeRowIndex, colIndex;
    			this.gridGroupingControl1.TableDescriptor.ColumnToRowColIndex(cd.MappingName, out relativeRowIndex, out colIndex);
    			Record r = this.gridGroupingControl1.Table.Records[0];
    			int recordRowIndex = this.gridGroupingControl1.Table.DisplayElements.IndexOf(r);
    			int rowIndex = recordRowIndex + relativeRowIndex;
    			GridTableCellStyleInfo style = this.gridGroupingControl1.Table.GetTableCellStyle(rowIndex, colIndex +this.gridGroupingControl1.
    			TableDescriptor.GetColumnIndentCount());
    			Console.WriteLine(style.TableCellIdentity.ToString());
    			Console.WriteLine(style.ToString());
    		}
    		else
    		{
    			// Newer code using new GetTableCellStyle overloads after version 3.0.0.16.
    			Record r = this.gridGroupingControl1.Table.Records[0];
    			GridTableCellStyleInfo style = this.gridGroupingControl1.Table.GetTableCellStyle(r, "Boolean");
    			Console.WriteLine(style.TableCellIdentity.ToString());
    			Console.WriteLine(style.ToString());
    		}  

Subscribe to the QueryValue and SaveValue events to save the unbound-field values.

    		private void grid_QueryValue(object sender, FieldValueEventArgs e)
    		{
    			e.Value = e.Record.ParentTable.Records.IndexOf(e.Record);
    		}