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

Custom PropertyDescriptor in GridBoundColumns

Before the DataSource is assigned to the grid, I'm setting up the gridBoundColumns using custom property descriptors in the GridBoundColumn constructor, based on user customization, so the user will use only the columns he needs. ... GridBoundColumn gridColumn = (new GridBoundColumn(new CustomPropertyDescritor(propertyName, isReadOnly))); gridColumn.MappingName = "name"; gridColumn.Header = "header"; gridDataBound.GridBoundColumns.Add(gridColumn) ... After the Grid DataSource is assigned all GridBoundColumn PropertyDescriptor Properties are changed to System.Component.ReflectedPropertyDescriptor. Is there any way to keep using the Custom Property Descriptors I created when GridBoundColumns were set up? Thanks Jose. I've created a class that wraps the DateTime structure called TimeStamp. The reasoning behind the wrapping is the ability to support nullable date/time properties. My date/time properties now look like: public TimeStamp PlannedTime { get; set; } And code can check for null-ness as needed e.g. if ( entry.PlannedTime != null ) { TimeSpan diff = entry.PlannedTime .... etc. My base class implements ICustomTypeDescriptor to provide a customized PropertyDescriptor implementation that makes the PlannedTime property appear to return a DateTime. The customized property descriptor then does any conversion needed in the GetValue/SetValue calls. This approach worked well for another 3rd party grid, but failed for the Essential Grid. It didn't appear to use the specialized PropertyDescriptor (for binding) returned by ICustomTypeDescriptor calls. Fortunately, I resolved the problem by implementing IConvertable and handling cell set events within Syncfusion i.e. the TimeStamp properties appear as either DateTime value or null to the Syncfusion grid. My question is: Is there anyway I can ensure that customized PropertyDescriptor implementations are used by all of the Essential Suite controls (rather than the default reflected property descriptors). I worked around the problem for my TimeStamp case, but customized PropertyDescriptor functionality can be pretty useful for implementing arbitrary plumbing across a range of Business components.

3 Replies

AD Administrator Syncfusion Team July 11, 2003 08:00 AM UTC

I may not understand your question. Here is a sample that creates a custom property descriptor (just lets you set the IsReadOnly attribute) for a column in a datatable, and uses it to create a GridBoundColumn for a GridDataBoundGrid before the datasource on the grid is set. It then sets the datasource to the grid. The grid does use the GridBoundColumn and reflects the readonly attribute set through the custom propertydescriptor. Is this what you needed?


AD Administrator Syncfusion Team July 11, 2003 11:05 AM UTC

> I may not understand your question. > > Here is a sample that creates a custom property descriptor (just lets you set the IsReadOnly attribute) for a column in a datatable, and uses it to create a GridBoundColumn for a GridDataBoundGrid before the datasource on the grid is set. It then sets the datasource to the grid. The grid does use the GridBoundColumn and reflects the readonly attribute set through the custom propertydescriptor. > > Is this what you needed? After you set the DataSource to the grid you lost your CustomPropertyDescriptor and the grid creates another "PropertyDescriptor" for you. If you check your example the CustomPropertyDescriptor becomes System.Data.DataColumnPropertyDescriptor. My question is, why I can not use the same CustomPropertyDescriptor (created before when GridBoundColumn was added) after the grid is binded? Thanks


AD Administrator Syncfusion Team July 12, 2003 06:47 AM UTC

During setting the DataSource to the grid, the grid retrieves the GridBoundColumn property descriptors directly from the DataSource where the type is still ProprtyDescriptor. One way around this problem might be to save the GridBoundColumn pd's before setting the DataSource, and restore them afterwards. Here is some code that seemed to work OK in that sample.
Hashtable savePDs = new Hashtable();
GridBoundColumnsCollection gbcc = this.gridDataBoundGrid1.GridBoundColumns;
if(gbcc.Count > 0)
{
	foreach(GridBoundColumn gbc in gbcc)
		savePDs.Add(gbc.MappingName, gbc.PropertyDescriptor);
}			 
this.gridDataBoundGrid1.DataSource = dt;
if(savePDs.Count > 0)
{
	foreach(string s in savePDs.Keys)
		gbcc[s].PropertyDescriptor = (PropertyDescriptor) savePDs[s];
}	
savePDs.Clear();

Loader.
Live Chat Icon For mobile
Up arrow icon