Hello Everyone, I hope everyone is having a nice day ;-)

I have a question about combo box and here is it...

I Have sex combo box(Male or Female only) and i want that when i choose Female it will have an id of 2(Male = 1, Female = 2)
without using SQL just VB.net only....

How should i do that? in such a way that, when i choose in a combo box about sex, it will have a corresponding number like 1 for Male or 2 for Female

Hi,
The combobox will take objects rather than just strings as it's items.

I tend to make a custom class I call it dataitem and give it a string property and a data property. You then can override the ToString to return your String value:

Class DataItem

Private _Data as object
Private _Text as string

Public Property Data as object
Get()
    Return _Data
End Get
Set (byVal value as object)
    _Data = value
End Set
End Property

Public Property Text
Get()
    Return _Text
End Get
Set (byVal value as string)
    _Text = value
End Set
End Property

Public Overrides Function ToString() As String
    Return _Text
End Function

Sub New (Optional byVal Data as Object = nothing, Optional ByVal Text as String ="")
    _Text = Text
    _Data = Data
End Sub

End Class

Now you can add your combobox items like this:

MyComboxbox.items.add( new DataItem(1,"Male"))
MyComboxbox.items.add( new DataItem(2, "Female"))

Then when you want to read the value:

dim DI as DataItem
dim MySex as integer
DI = MyCombobox.SelectedItem

MySex = cint(DI.Data)
This question has already been answered. Start a new discussion instead.