473,386 Members | 1,790 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,386 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 1576
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.