This message was discovered on microsoft.public.dotnet.framework.windowsforms.designtime.
| Frederic Goulet |
Hi, In C#, I want to provide my own form to edit collection in the standard CollectionEditor. The documentation for the CollectionEditor.CreateCollectionForm method state:
Remarks Notes to Inheritors: You can inherit from CollectionEditor.CollectionForm to provide your own form.
But when I try to create such a new class,
public class MyCollectionForm : System.ComponentModel.Design.CollectionEditor.CollectionForm {
}
I got the error:
'System.ComponentModel.Design.CollectionEditor.CollectionForm' is inaccessible due to its protection level'
What I am missing here?
Thanks a lot
Frederic Goulet
|
|
|
| |
|
| |
| |
| John Socha-Leialoha |
The CollectionEditor.CollectionForm is marked as protected, so it's not available outside the CollectionEditor class. What this means is that you have to subclass the CollectionEditor class, then inside this subclass, create a subclass of the CollectionForm class. Something like this:
public class MyCollectionEditor : CollectionEditor { private class MyCollectionForm : CollectionEditor.CollectionForm { } }
Hope that helps. -- John
"Frederic Goulet" <Click here to reveal e-mail address> wrote in message news:u8pgJEXECHA.2236@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
| |
| Frederic Goulet |
Thanks very much.
Frederic Goulet
"John Socha-Leialoha" <Click here to reveal e-mail address> a écrit dans le message de news: O2hBAMXECHA.2400@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
|
| |
|
|
| |
| abhishek ghuwalewala |
The problem is that System.ComponentModel.Design.CollectionEditor.CollectionForm is a protected class. When you derive from a protected class you cannot change its accessibility. The MyCollectionForm class is being exposed a public class although it is derived from a protected class. If you change your class definition to:
protected class MyCollectionForm : System.ComponentModel.Design.CollectionEditor.CollectionForm {
}
the error should go away.
A/G
"Frederic Goulet" <Click here to reveal e-mail address> wrote in message news:u8pgJEXECHA.2236@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
| |
| Shawn Burke [MSFT] |
You also need to do so from within your CollectionEditor derivation...
public class MyCollectionEditor : CollectionEditor { protected class MyCollectionForm : CollecitonEditor.CollectionForm { } }
--
Please do not reply to this alias directly. This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. © 2002 Microsoft Corporation. All rights reserved.
"abhishek ghuwalewala" <Click here to reveal e-mail address> wrote in message news:OGmNHKXECHA.2440@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
| |
| |
| Frederic Goulet |
Thanks to both of you, it works now.
But, is there a way to inherit from the standard Collection Editor Form? Because, what I want to do is to only add a button to the existing form that already have all the stuff to edit collections like the list of items, the Add/Remove buttons, the PropertyGrid etc...
Thanks
Frederic Goulet
"Shawn Burke [MSFT]" <Click here to reveal e-mail address> a écrit dans le message de news: OJ64jMXECHA.1752@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| John Socha-Leialoha |
Try something like the following. I've tried this sample and it works. using System; using System.ComponentModel.Design; using System.Drawing; using System.Windows.Forms;
namespace TestEditor { public class MyCollectionEditor : CollectionEditor { public MyCollectionEditor(Type type) : base(type) { }
protected override CollectionForm CreateCollectionForm() { CollectionForm theForm = base.CreateCollectionForm(); Form form = (Form) theForm;
Button button = new Button(); button.Name = "btnTest"; button.Location = new Point(10, form.ClientRectangle.Bottom - 35); button.Anchor = AnchorStyles.Bottom; button.Size = new Size(68,24); button.Text = "Test"; button.Click += new EventHandler(this.OnClick); form.Controls.Add(button); return theForm; }
private void OnClick(object sender, EventArgs e) { MessageBox.Show("Got here."); } } }
"Frederic Goulet" <Click here to reveal e-mail address> wrote in message news:uj#9UIYECHA.1360@tkmsftngp05... [Original message clipped]
|
|
|
| |
|
| |
| |
| Frederic Goulet |
Awesome! That's exactly what I was looking for!
Thanks a million times John.
Frederic "John Socha-Leialoha" <Click here to reveal e-mail address> a écrit dans le message de news: O1c$5PjECHA.2440@tkmsftngp02... Try something like the following. I've tried this sample and it works. using System; using System.ComponentModel.Design; using System.Drawing; using System.Windows.Forms;
namespace TestEditor { public class MyCollectionEditor : CollectionEditor { public MyCollectionEditor(Type type) : base(type) { }
protected override CollectionForm CreateCollectionForm() { CollectionForm theForm = base.CreateCollectionForm(); Form form = (Form) theForm;
Button button = new Button(); button.Name = "btnTest"; button.Location = new Point(10, form.ClientRectangle.Bottom - 35); button.Anchor = AnchorStyles.Bottom; button.Size = new Size(68,24); button.Text = "Test"; button.Click += new EventHandler(this.OnClick); form.Controls.Add(button); return theForm; }
private void OnClick(object sender, EventArgs e) { MessageBox.Show("Got here."); } } }
"Frederic Goulet" <Click here to reveal e-mail address> wrote in message news:uj#9UIYECHA.1360@tkmsftngp05... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
|