Multimobile Development: Building Applications for any Smartphone
Custom CollectionEditor CollectionForm
Messages   Related Types
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

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
New book project – Multimobile Development: Building Applications for any Smartphone
Dive into HTML5
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
Steve Jobs’ thoughtful/thought provoking Thoughts on Flash…
Handy list of countries in CSV format
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
 
System.ComponentModel.Design.CollectionEditor
System.Drawing.Point
System.Drawing.Size
System.EventArgs
System.EventHandler
System.Web.UI.WebControls.Button
System.Windows.Forms.AnchorStyles
System.Windows.Forms.Button
System.Windows.Forms.MessageBox
System.Windows.Forms.PropertyGrid




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734