I extended a combo box control to make some of my common functions a little
simpler. But now I would like to add a Tag property to the Items in the
combo box, as far as I can tell they dont' have one in the standard control.
My question is... Can I add this property without having to extend the
System.Windows.Forms.ComboBox.ObjectCollection class?
and if thats what I have to do.. how do I make my combobox use my
objectcollection instead of the one provided with the framework
Thanks... If you have another method to store a simple string along with an
item (like the tag property of many items) in the combo box I'm all ears too
-Kyle
-Kevin Buchan
kevin....@REMOVETHISTOEMAILtroutmansanders.com
On Wed, 6 Aug 2003 11:09:11 -0700, "Kyle Klaus" <ky...@electdesign.net>
wrote:
Public Class ComboListboxItem
Private _ItemData
Private _displayedName As String
Public Sub New(ByVal ItemData As Object, ByVal displayedName As String)
_ItemData = ItemData
_displayedName = displayedName
End Sub
Public ReadOnly Property itemdata() As Object
Get
Return _ItemData
End Get
End Property
Public ReadOnly Property Name()
Get
Return _displayedName
End Get
End Property
Public Overrides Function tostring() As String
Return _displayedName
End Function
End Class
FILL COMBO:
With cboRIstate
.Sorted = True
.Items.Add(New ComboListboxItem("MYitemData1", "MydisplayText1"))
.Items.Add(New ComboListboxItem("myItemData2", "mydisplayText2"))
.Items.Add(New ComboListboxItem(Nothing, "--"))
.SelectedIndex = 0
End With
GET VALUE:
if not ctype(cboRIstate.selecteditem,ComboListboxItem).itemdata is nothing
then
msgbox ctype(ctype(cboRIstate.selecteditem,ComboListboxItem).itemdata
,string)
end if
"Kyle Klaus" <ky...@electdesign.net> schrieb:
> I extended a combo box control to make some of my
> common functions a little simpler. But now I would like
> to add a Tag property to the Items in the combo box,
> as far as I can tell they dont' have one in the standard control.
>
> My question is... Can I add this property without having
> to extend the System.Windows.Forms.ComboBox.
> ObjectCollection class?
\\\
Dim p As New Person()
p.Name = "Pink Panther"
p.Age = 22
Me.ComboBox1.Items.Add(p)
MessageBox.Show( _
DirectCast(Me.ComboBox1.Items.Item(0), Person).ToString() _
)
.
.
.
Public Class Person
Private m_strName As Object
Private m_intAge As Integer
Public Property Name() As String
Get
Return m_strName
End Get
Set(ByVal Value As String)
m_strName = Value
End Set
End Property
Public Property Age() As Integer
Get
Return m_intAge
End Get
Set(ByVal Value As Integer)
m_intAge = Value
End Set
End Property
Public Overrides Function ToString() As String
Return m_strName & " (" & m_intAge.ToString() & ")"
End Function
End Class
///
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet