.NET Framework Bookmark and Share   
 index > .NET Base Class Library > PropertyGrid with disabled Add - button
 

PropertyGrid with disabled Add - button

Hi all!

I'm using a PropertyGrid to create a DataTable.
The DataTable has a Columns - property.
When I open the Collection Editor on the columns property the Add and Remove buttons are diabled. Why?
The DataColumn does have a constructor without parameters.

Hope you can help.



Lars Skov
Lars Skov
I stand somewhat corrected. When I originally looked at the editor used for the collection I happened to look at the wrong one (DataColumnEditor) rather than the actual one (ColumnCollectionEditor). So much for consistent naming in the framework.

The column collection uses a custom collection editor deriving from the standard collection editor. This is pretty typical for a collection. The base class provides Add/Remove functionality but only if the derived type supports it. In this case the ColumnCollectionEditor does not expose the appropriate information to allow the addition of new columns. I don't know why MS made this decision as it seems that creating new columns should be doable in the editor. Nevertheless it is currently disabled. Note that you can use INS and DEL to add and remove columns but the changes are lost when the editor closes.

I would recommend that if you want this functionality that you submit a change request to http://connect.microsoft.com. It seems like it would be a reasonable change to make.

Michael Taylor - 3/12/09
http://p3net.mvps.org
TaylorMichaelL
The column editor does not support adding or removing the columns in the table. If you want this functionality then you'll have to create a custom editor.

Michael Taylor - 3/11/09
http://p3net.mvps.org
TaylorMichaelL
Hi

As I undestand the PropertyGrid it's column editor support adding and removing in collections and the DataTable.Columns is a DataColumnCollection.


Lars Skov
Lars Skov
I stand somewhat corrected. When I originally looked at the editor used for the collection I happened to look at the wrong one (DataColumnEditor) rather than the actual one (ColumnCollectionEditor). So much for consistent naming in the framework.

The column collection uses a custom collection editor deriving from the standard collection editor. This is pretty typical for a collection. The base class provides Add/Remove functionality but only if the derived type supports it. In this case the ColumnCollectionEditor does not expose the appropriate information to allow the addition of new columns. I don't know why MS made this decision as it seems that creating new columns should be doable in the editor. Nevertheless it is currently disabled. Note that you can use INS and DEL to add and remove columns but the changes are lost when the editor closes.

I would recommend that if you want this functionality that you submit a change request to http://connect.microsoft.com. It seems like it would be a reasonable change to make.

Michael Taylor - 3/12/09
http://p3net.mvps.org
TaylorMichaelL

You can use google to search for other answers

Custom Search

More Threads

• SDK class not registered
• DataSource Default Property Editor
• how do I get current system time
• how to detect parameter values passed to method
• Global Data Classes
• Exception on DirectoryInfo.SetAccessControl()
• Error calling asp.net window from asp application
• serialport returns unspecified values
• multilanguage application in one exe?
• Assembly reference?