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.

Custom PropertyDescriptor in GridBoundColumns

Thread ID:

Created:

Updated:

Platform:

Replies:

5617 Jul 10,2003 11:52 AM Jul 12,2003 02:47 AM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On July 10, 2003 11:52 AM

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.

Administrator [Syncfusion]
Replied On July 11, 2003 04:00 AM

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?

Administrator [Syncfusion]
Replied On July 11, 2003 07:05 AM

> 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

Administrator [Syncfusion]
Replied On July 12, 2003 02:47 AM

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

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.

;