Home All Groups Group Topic Archive Search About

How to create a "DataSource" & "Items" properties on Custom Combob

Author
17 Jan 2006 3:38 PM
VB Newbie
I am creating a user control containing a combobox using VB.NET(2003)
I want to add 2 public properties "DataSource" and "Items" like the
"System.Windows.Forms.ComboBox"

here is my code, but it doesn't work. What's wrong with it?

Public Property cboDataSource() As Object
       Get
           Return Me.cbo.DataSource    'cbo is my combobox
       End Get
       Set(ByVal Value As Object)
           Me.cbo.DataSource = Value
       End Set
End Property

Public Property cboItems() As System.Windows.Forms.ComboBox.ObjectCollection
        Get
            Return Me.cbo.Items
        End Get
        Set(ByVal Value As System.Windows.Forms.ComboBox.ObjectCollection)
            Me.cbo.Items.Add(Value)
        End Set
End Property

Author
17 Jan 2006 4:23 PM
Chris
VB Newbie wrote:
Show quoteHide quote
> I am creating a user control containing a combobox using VB.NET(2003)
> I want to add 2 public properties "DataSource" and "Items" like the
> "System.Windows.Forms.ComboBox"
>
> here is my code, but it doesn't work. What's wrong with it?
>
> Public Property cboDataSource() As Object
>        Get
>            Return Me.cbo.DataSource    'cbo is my combobox
>        End Get
>        Set(ByVal Value As Object)
>            Me.cbo.DataSource = Value
>        End Set
> End Property
>
> Public Property cboItems() As System.Windows.Forms.ComboBox.ObjectCollection
>         Get
>             Return Me.cbo.Items
>         End Get
>         Set(ByVal Value As System.Windows.Forms.ComboBox.ObjectCollection)
>             Me.cbo.Items.Add(Value)
>         End Set
> End Property
>
>

Why is the problem you are having with it?


-First problem I see is that you are mixing ideas here.  You are trying
to add an ObjectCollection to the collection.  You should be additem the
item.  Let's say you were using strings (you could use object also, or
datarow if your datasource is a datatable)

Public Property cboItems(Index as integer) As String
          Get
              Return Me.cbo.Items(Index).toString
          End Get
          Set(ByVal Value As String)
              Me.cbo.Items.Add(Value)
          End Set
End Property

Hope it helps
Author
18 Jan 2006 2:22 AM
VB Newbie
After applying your code, I can't view the "cboitem" property in VS.NET
designer view. How can I edit the "cboitem" and "cboDatasource" property in
designer view like "System.Windows.Forms.ComboBox"'s one?

Show quoteHide quote
"Chris" wrote:
>
> Why is the problem you are having with it?
>
> -First problem I see is that you are mixing ideas here.  You are trying
> to add an ObjectCollection to the collection.  You should be additem the
> item.  Let's say you were using strings (you could use object also, or
> datarow if your datasource is a datatable)
>
> Public Property cboItems(Index as integer) As String
>           Get
>               Return Me.cbo.Items(Index).toString
>           End Get
>           Set(ByVal Value As String)
>               Me.cbo.Items.Add(Value)
>           End Set
> End Property
>
> Hope it helps
>
Author
18 Jan 2006 10:13 AM
Cor Ligthert [MVP]
VB Newbie,

Would it be not more advisable first to use the normal combobox in a bounded
and not bounded way. From your sample and question, is it clear for me that
you have not yet everything clear for yourself about the combobox.

However feel free to go on this way.

Cor
Author
22 Jan 2006 2:20 PM
VB Newbie
How can I move on this way?
would you mind give me some hints?

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> VB Newbie,
>
> Would it be not more advisable first to use the normal combobox in a bounded
> and not bounded way. From your sample and question, is it clear for me that
> you have not yet everything clear for yourself about the combobox.
>
> However feel free to go on this way.
>
> Cor
>
>
>
Author
23 Jan 2006 8:09 AM
Cor Ligthert [MVP]
VB Newbie,

> How can I move on this way?
> would you mind give me some hints?
>
I have searched on MSDN, i found this page maybe is it something for you.

http://msdn2.microsoft.com/en-us/library/k0e26a9k.aspx

I hope this helps,

Cor