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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
VB said:
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
 
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?
 
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
 
Back
Top