icsharpcode / SharpDevelop

#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
2.09k stars 773 forks source link

Custom Column Collection Editor not used in Forms Designer #219

Open dgrunwald opened 10 years ago

dgrunwald commented 10 years ago

SD-1879, originally created on 1/21/2012 16:39:09 by Matt Ward

Attached project contains a C# winforms project with the ObjectListView control from:

http://objectlistview.sourceforge.net/cs/index.html

1) Open the MainForm.cs and switch to the designer. 2) Select the list view right click and select Edit Columns. 3) Click the Add button.

Expected result:

A new column can be added.

Actual result:

System.Exception: The control BrightIdeasSoftware.ObjectListView has thrown an unhandled exception in the designer and has been disabled.  

Exception:

Unable to cast object of type 'System.Windows.Forms.ColumnHeader' to type 'BrightIdeasSoftware.OLVColumn'.

Stack trace:

   at BrightIdeasSoftware.ObjectListView.GetColumn(Int32 index)

   at BrightIdeasSoftware.ObjectListView.HandleNotify(Message& m)

   at BrightIdeasSoftware.ObjectListView.WndProc(Message& m) ---> System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.ColumnHeader' to type 'BrightIdeasSoftware.OLVColumn'.

   at BrightIdeasSoftware.ObjectListView.GetColumn(Int32 index)

   at BrightIdeasSoftware.ObjectListView.HandleNotify(Message& m)

   at BrightIdeasSoftware.ObjectListView.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    at System.Windows.Forms.Design.ControlDesigner.DesignerWindowTarget.DefWndProc(Message& m)    at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)    at System.Windows.Forms.Design.g.WndProc(Message& m)    at System.Windows.Forms.Design.ControlDesigner.DesignerWindowTarget.OnMessage(Message& m)

Looking at the ObjectListView assembly it defines a custom UITypeEditor for the column headers which SharpDevelop does not seem to be using.

[Editor("BrightIdeasSoftware.Design.OLVColumnCollectionEditor", "System.Drawing.Design.UITypeEditor")]         public new ListView.ColumnHeaderCollection Columns

Visual Studio does seem to use this UITypeEditor. You can see OLVColumn in the dialog's title.

irneb commented 10 years ago

I can corroborate this. Still same issue.

It also happens on any custom component derived from ListView. It's as if #Dev's property grid doesn't read the Editor assigned to properties which have been replaced using the new keyword (only working on virtual / override).

But due to this particular property (Columns) of the original ListView not being declared virtual, the only choice to re-use is with new.