472,119 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Combobox Display/Value

Is it possible to manually provide (display,value) pairs for a combo box??
The only method I'm aware of is bind the "displaymember" and "valuemember"
properties of the combobox to columns in a datatable.

I want to be able to add items to the combobox and be able to give my own
values for the valuemember property...is this possible??

Thanks.
Nov 21 '05 #1
1 1519
Parveen,

Yes, it is possible.

You start off by creating your own class that contains its own properties, like this:

Public Class Person

Private _strFName As String

Private _strPID As String

Public Property FirstName() As String

Get

Return _strFName

End Get

Set(ByVal Value As String)

_strFName = Value

End Set

End Property

Public Property PersonId() As String

Get

Return _strPID

End Get

Set(ByVal Value As String)

_strPID = Value

End Set

End Property

Public Overrides Function ToString() As String

Return FirstName

End Function

End Class

Next, add to your combobox and set the valuemember and displaymember like so:

Dim PColl(3) As Person

PColl(0) = New Person

PColl(0).FirstName = "Ed"

PColl(0).PersonId = "JFIE663"

PColl(1) = New Person

PColl(1).FirstName = "Rick"

PColl(1).PersonId = "JIUE32"

PColl(2) = New Person

PColl(2).FirstName = "Mike"

PColl(2).PersonId = "KEU98"

PColl(3) = New Person

PColl(3).FirstName = "HomerJSimpson"

PColl(3).PersonId = "ID10T"

For i As Integer = 0 To 3

Me.ComboBox1.Items.Add(PColl(i))

Next

Me.ComboBox1.DisplayMember = "FirstName"

Me.ComboBox1.ValueMember = "PersonId"
HTH
S.M. Altaf [MVP]

--------------------------------------------------------------------------------

All that glitters has a high refractive index.
www.mendhak.com
"Parveen" <Pa*****@discussions.microsoft.com> wrote in message news:76**********************************@microsof t.com...
Is it possible to manually provide (display,value) pairs for a combo box??
The only method I'm aware of is bind the "displaymember" and "valuemember"
properties of the combobox to columns in a datatable.

I want to be able to add items to the combobox and be able to give my own
values for the valuemember property...is this possible??

Thanks.
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by NCrum | last post: by
reply views Thread by dbuchanan | last post: by
2 posts views Thread by AMDRIT | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.