473,225 Members | 1,264 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 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 1563
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
4
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank...
0
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
by: AMDRIT | last post by:
Hello Everyone, I would like to format the Display Members of a combobox's datasource. Is there a way to apply a format without subclassing the original datasource? For example, given a list of...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
19
by: active | last post by:
I'm using a ComboBox to display objects of a class I've defined, say CQQ. Works great except somehow I occasionally set an Item to a String object instead of an object of type CQQ. It looks...
7
by: creative1 | last post by:
hi, I have a simple query. I have a dynamic combobox when I select one value fromt he combobox; on click a function is called that display the value of the combobox(i.e not same as text list of...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.