HOWTO : Design-time custom collection editing for custom control 
Author Message
 HOWTO : Design-time custom collection editing for custom control

Hi!

I have wrote a control that, among other things, consists of one collection
(collection which derives from CollectionBase, and whose items are of my own
class). Now what I must do so that in design-time users of that control can
click on the three dots (of the collection property) in the property viewer
in VS.NET and they get a standard CollectionEditor (just like you edit
ColumnHeaderCollection or ListViewItemsCollection in ListView control)! It
must modify code because when you add item it is added in code!

In other words, does anybody know how to make custom collections design-time
compatible!

Thanks!



Thu, 26 May 2005 18:53:56 GMT  
 HOWTO : Design-time custom collection editing for custom control
Hello Goran,

If you only want the IDE generate the code for your collection, the
DesignerSerializationVisibilityAttribute is helpful. Setting the visibility
to Content causes the designer to serialize the contents of the property,
rather than the property itself. An example of this is a property that
provides access to the items in a collection. There is a sample code:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }

You may refer to the link below to get more detailed information about
DesignerSerializationVisibilityAttribute Class:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemCompone...
DesignerSerializationVisibilityAttributeClassTopic.asp

If you want to create you owner Editor for your collection property and
control the code generating, you may write a Designer (such collection
Editor) to do it. For more detailed information about it please see:

Customizing Code Generation in the .NET Framework Visual Designers
http://msdn.microsoft.com/library/en-us/dndotnet/html/custcodegen.asp

I hope it helps you.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Subject: HOWTO : Design-time custom collection editing for custom
control
    Date: Sun, 8 Dec 2002 11:53:56 +0100
    Organization: CARNet, CROATIA
    Lines: 16

    NNTP-Posting-Host: a5.cmu.carnet.hr
    X-Trace: bagan.srce.hr 1039344822 19501 193.198.128.6 (8 Dec 2002
10:53:42 GMT)

    NNTP-Posting-Date: 8 Dec 2002 10:53:42 GMT
    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
    Path:
cpmsftngxa09!cpmsftngxa10!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
!nautilus.eusc.inter.net!fu-berlin.de!carnet.feed!CARNet.hr!not-for-mail
    Xref: cpmsftngxa09 microsoft.public.dotnet.languages.csharp:114816
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    Hi!

    I have wrote a control that, among other things, consists of one
collection
    (collection which derives from CollectionBase, and whose items are of
my own
    class). Now what I must do so that in design-time users of that control
can
    click on the three dots (of the collection property) in the property
viewer
    in VS.NET and they get a standard CollectionEditor (just like you edit
    ColumnHeaderCollection or ListViewItemsCollection in ListView control)!
It
    must modify code because when you add item it is added in code!

    In other words, does anybody know how to make custom collections
design-time
    compatible!

    Thanks!



Sat, 28 May 2005 22:15:32 GMT  
 HOWTO : Design-time custom collection editing for custom control
Ok!

First thanks for your reply! Now I am on the right path! But if you can
please help me a bit more so I don't loose much time!

I have a class that describes a collection item :
-------------------------------------------------

public class ControlCollectionItem
{
  private string sText="";
  private Image iImage;

  public ControlCollectionItem(string sButtonText,Image iButtonImage)
  {
    sText=sButtonText;
    if (iButtonImage!=null)
      iImage=(Image)iButtonImage.Clone();
  }

Quote:
}

Here I have a collection :
--------------------------

public class ControlCollection : System.Collections.CollectionBase
{
  public void Add(ControlCollectionItem gpp)
    {  
    List.Add(gpp);

  public void Remove(int index)
  {
    if (index > Count - 1 || index < 0)
    {
      System.Windows.Forms.MessageBox.Show("Index not valid!");
    }
    else
    {
      List.RemoveAt(index);
    }
  }

  new public void Clear()
  {
    List.Clear();
  }

  public ControlCollectionItem this[int iIndex]
  {
    get
    {
      if (iIndex > Count - 1 || iIndex < 0)
      return null;
    else
      return (GentoPickerPage)List[iIndex];
    }
  }

Quote:
}

Now in control I have this :
----------------------------

.
.
.

private ControlCollection controlCollection1=new ControlCollection();

public ControlCollection CollectionProperty
{
  get
  {
    return controlCollection1;
  }

Quote:
}

.
.
.

What I must implement in this property and in ControlCollectionItem
class and in ControlCollection class so that you can add items in that
collection at design time!

Thanks in advance!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 29 May 2005 00:27:24 GMT  
 HOWTO : Design-time custom collection editing for custom control
Ok!

First thanks for your reply! Now I am on the right path! But if you can
please help me a bit more so I don't loose much time!

I have a class that describes a collection item :
-------------------------------------------------

public class ControlCollectionItem
{
  private string sText="";
  private Image iImage;

  public ControlCollectionItem(string sButtonText,Image iButtonImage)
  {
    sText=sButtonText;
    if (iButtonImage!=null)
      iImage=(Image)iButtonImage.Clone();
  }

Quote:
}

Here I have a collection :
--------------------------

public class ControlCollection : System.Collections.CollectionBase
{
  public void Add(ControlCollectionItem gpp)
    {  
    List.Add(gpp);

  public void Remove(int index)
  {
    if (index > Count - 1 || index < 0)
    {
      System.Windows.Forms.MessageBox.Show("Index not valid!");
    }
    else
    {
      List.RemoveAt(index);
    }
  }

  new public void Clear()
  {
    List.Clear();
  }

  public ControlCollectionItem this[int iIndex]
  {
    get
    {
      if (iIndex > Count - 1 || iIndex < 0)
      return null;
    else
      return (GentoPickerPage)List[iIndex];
    }
  }

Quote:
}

Now in control I have this :
----------------------------

.
.
.

private ControlCollection controlCollection1=new ControlCollection();

public ControlCollection CollectionProperty
{
  get
  {
    return controlCollection1;
  }

Quote:
}

.
.
.

What I must implement in this property and in ControlCollectionItem
class and in ControlCollection class so that you can add items in that
collection at design time!

Thanks in advance!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 29 May 2005 00:39:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Can not add a custom .NET control on the form in design-time

2. Custom control fire NullReferenceException at design time

3. Custom control properties and VB design time

4. Custom control with no border at design time.

5. Custom Design Time Wizards

6. Collection Editor for my Custom Control

7. Binding a DataGrid Web Control to a Collection of Custom Classes

8. help with custom controls and collections

9. Custom Control Design Help

10. Printing the Client Area of a custom-designed ActiveX Control

11. Subclassing an edit control to do custom word wrapping

12. how to edit custom list-control items without having the window focused

 

 
Powered by phpBB® Forum Software