Results 1 to 16 of 16

Thread: [RESOLVED] Custom Collection

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Resolved [RESOLVED] Custom Collection

    I have been researching for a couple of days now and to no avail. Does Anyone know how to make a custom collection that take advantage of the collection editor? Code or an actual file would be greatly appreciated. I would like to be able to have 3 Color Values, 1 Boolean and 1 String. If anyone can help me with this, please do.

    E

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Custom Collection

    vb.net Code:
    1. Public Class MyData
    2.     Public C1 As Color
    3.     Public C2 As Color
    4.     Public C3 As Color
    5.     Public Flag As Boolean
    6.     Public Text As String
    7. End Class
    8.  
    9. Public Class SomeClass
    10.     Public col As New List(Of MyData)
    11. End Class

    What is collection editor?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    Collection Editor is That dialog Box that allows you to define stuff in a drop down menu or such. It opens when you click the ... on any value that says (Collection)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    Does Anyone know? I know it is possible because I have seen it used in advanced User Controls. If anyone knows, Please step forward.

    E

  5. #5
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Custom Collection

    Create a new class as follows:

    vb Code:
    1. Imports System.ComponentModel
    2. Imports System.ComponentModel.Design
    3. Imports System.Drawing.Design
    4.  
    5. Public Class Class1
    6.     Inherits Control
    7.     Private mc_asd As New List(Of TestItem)
    8.     <Editor(GetType(CollectionEditor), GetType(UITypeEditor)), _
    9. DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(True), _
    10. System.ComponentModel.DisplayName("Selector Items")> _
    11. Public Property asd() As List(Of TestItem)
    12.         Get
    13.             Return mc_asd
    14.         End Get
    15.         Set(ByVal value As List(Of TestItem))
    16.             mc_asd = value
    17.         End Set
    18.     End Property
    19. End Class
    20.  
    21. <Serializable()> _
    22. Public Class TestItem
    23.     Dim mc_Text As String
    24.  
    25.     Public Sub New(ByVal theText As String)
    26.         Text = theText
    27.     End Sub
    28.  
    29.     Public Sub New()
    30.         '
    31.     End Sub
    32.  
    33.     <System.ComponentModel.Description("Display Text For the Item"), System.ComponentModel.Category("Item")> _
    34.     Public Property Text() As String
    35.         Get
    36.             Return mc_Text
    37.         End Get
    38.         Set(ByVal value As String)
    39.             mc_Text = value
    40.         End Set
    41.     End Property
    42.  
    43. End Class

    check out the asd property in the designer...

    (i always call junk asd)

    Kris

  6. #6
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Custom Collection

    oh and as per usual override the tostring function if you want to change the text of each item...

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    I am getting a Blue Zig-zag line under CollectionEditor It says 'Type CollectionEditor is not defined' What do I do?

    E

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    Also, If you could make it have the items I defined and then give it to me. I am Afraid I am not a pro a VB.Net.

    Thanks for your time and Help!

    E

  9. #9
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Custom Collection

    add a reference to system.design i think (from memory)

    Kris

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    That Didn't Exist. Here are the current references:
    Imports System.ComponentModel
    Imports System.ComponentModel.Design
    Imports System.Drawing.Design

  11. #11
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Custom Collection

    it should exist - just checked it...
    here's a sample project:
    Attached Files Attached Files

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    Great! That Works! Thanks for your time!

    E
    P.S. Is there a way to make it one of those bottom bar object like timers are?

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    How would I go about adding The Items I specified I just Cannot figure it out... I appreciate your time and effort, it is just that I am not Extremely Advanced so, if you can find the time could you make It with the Things I specified? I would greatly Appreciate it.

    Thanks!
    E

  14. #14
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Custom Collection

    well add stuff like:
    vb Code:
    1. Dim mc_Color As Color = Drawing.Color.Red
    2.     <System.ComponentModel.Description("Sets the color for Item"), System.ComponentModel.Category("Item")> _
    3.     Public Property Color() As Color
    4.         Get
    5.             Return mc_Color
    6.         End Get
    7.         Set(ByVal value As Color)
    8.             mc_Color = value
    9.         End Set
    10.     End Property
    bit in the TestItem class...

    Kris

  15. #15
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Custom Collection

    If you want to customize the CollectionEditor window more, you have to create your own class that derives from CollectionEditor. You can override many methods and properties and customize it the way you like.

    vb.net Code:
    1. Public Class CustomColEditor
    2.    Inherits CollectionEditor
    3.  
    4.    Public Sub New(ByVal type As Type)
    5.       MyBase.New(type)
    6.    End Sub
    7.  
    8.    'override properties/methods
    9. End Class

    To use, simply set it as the CollectionEditor instead of the base 'CollectionEditor' as in i00's code:
    Code:
    <Editor(GetType(CustomColEditor), GetType(UITypeEditor))> _
    Public Property ...
    For a simple example, see my WizardControl (or possibly other controls I created, can't really remember). I needed to use it because I had a collection of Controls, and I needed the editor to create WizardPages, instead of the generic Controls.
    There is a method called something like CreateCollectionType (of ItemType, can't remember), which should return the type that the collection editor modifies. If the collection itself is a strongly bound list (List(Of T)) then it should do that automatically, but in my case it was a ControlCollection so it doesn't.
    There is also an array variant of that method which allows you to specify multiple types. The 'Add' button then changes into a dropdown button and you can choose one of the types. For an example on that, see my advanced ToolstripContainer control. It can create both ToolStrips and MenuStrips from the same collection editor.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    76

    Re: Custom Collection

    Excellent! That works Fantastically! Thank you for your time!

    E

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width