473,404 Members | 2,195 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,404 software developers and data experts.

Combobox - How to match item index with record ID

Table A has 2 columns:
recID int
recName String

I need to load all recName into combobox B using B.Items.Add(recName). This
is no problem.
However, I would like to be able to match ComboxBox B's index with table A's
recID so that I can use B.SelectedIndex to update any table that uses Table
A's recID. Currently, I have to use a clumsy routine to find recID from
B.text
Any help is greatly appreciated.
Thanks

Bill
Nov 21 '05 #1
11 2571
Change from using Items.Add to a method that uses DataSource and
DisplayMember -- this will allow you to bind a more complex data object
to the ComboBox while maintaining other (non-visible) information -- a
DataView will allow you to filter the orginal data and is bindable to a
combobox (any class that implements IList is bindable)

Nov 21 '05 #2
May I have some sample codes to review?
Thanks
Bill

"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Change from using Items.Add to a method that uses DataSource and
DisplayMember -- this will allow you to bind a more complex data object
to the ComboBox while maintaining other (non-visible) information -- a
DataView will allow you to filter the orginal data and is bindable to a
combobox (any class that implements IList is bindable)

Nov 21 '05 #3
Bill,
\\\
Private Loaded as Boolean
////
\\\\
B.Datasource = A
B.DisplayMember = "recName"
B.ValueMember = "recId"
Loaded = true
///
At SelectedIndexChange
\\\
if Loaded then
Dim theId = B.SelectedValue
End if
////

I hope this helps,

Cor
Nov 21 '05 #5
Cor;

This helps, definitely!

However, the combobox somehow display the Valuemember instead of
DisplayMember!
What did I do wrong?

Thanks
Bill
-----------
Here's my codes:
Private Function AddTestItem()

Dim dMySet As DataSet

Dim dmySQL As String

dmySQL = "SELECT * from MP_PreferredRoadTemplate"

dMySet = MAPPOINTDataBoss.dWFIRecView(dmySQL)

' MsgBox(dMySet.Tables(0).Rows.Count)

Dim cbTest As New ComboBox

cbTest.DataSource = dMySet.Tables(0)

cbTest.ValueMember = "roadTemplateID"

cbTest.DisplayMember = "roadTemplatename"
End Function

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Bill,
\\\
Private Loaded as Boolean
////
\\\\
B.Datasource = A
B.DisplayMember = "recName"
B.ValueMember = "recId"
Loaded = true
///
At SelectedIndexChange
\\\
if Loaded then
Dim theId = B.SelectedValue
End if
////

I hope this helps,

Cor

Nov 21 '05 #6
methinks that this isn't the combobos that you are seeing... I don't
see you adding it to the form...

create the combobox on the form and then set its properties in the
method...

Nov 21 '05 #7
Bill,

However, the combobox somehow display the Valuemember instead of
DisplayMember!
What did I do wrong?


Can you show that piece of code frome you,

Cor
Nov 21 '05 #8
Cor & Stand__Sure;
I've tried several things and it's still NOT working properly.
I have a combobox (cbServiceCode) created on the form, so there's no need to
initialize the combobox

below is the code. I hope that you can help me to solve the problem!
Thanks in advance

Bill
1. Use a dataset as cbServiceCode.DataSource. Got error Cannot add new
valuemember!

Private Function AddServiceCode()

Dim dS As DataSet

Dim dSQL As String

Dim mServiceCode, mServiceDesc, mServiceID As String

' Dim mServiceID As Integer

dSQL = "Select * from AC_oxyServices order by oxyServiceCode "

dS = AC_DataBoss.dWFSelectView(dSQL)

cbServiceCode.DataSource = dS

cbServiceCode.DisplayMember = "oxyservicecode"

cbServiceCode.ValueMember = "oxyserviceid"

End Function

2. Use an ArrayList as datasource along with a class (AC_DisplayList)
showing longname and shortname

I got err msg "Argument Prompt cannot be converted to type String" everytime
I click on the box

The box shows the Valuemember instead of displaymember!

Private Function AddServiceCode()

Dim dS As DataSet

Dim dSQL As String

Dim mServiceCode, mServiceDesc, mServiceID As String

' Dim mServiceID As Integer

dSQL = "Select * from AC_oxyServices order by oxyServiceCode "

dS = AC_DataBoss.dWFSelectView(dSQL)

' MsgBox(dS.Tables(0).Rows.Count)

Dim dSRow As DataRow


' Populates the list box using DataSource.

' DisplayMember is used to display just the long name of each state.

Dim mServiceArray As New ArrayList

For Each dSRow In dS.Tables(0).Rows

mServiceCode = Trim(dSRow.Item("oxyServiceCode"))

mServiceDesc = Trim(dSRow.Item("oxyServiceDesc"))

mServiceID = CStr(dSRow.Item("oxyServiceID"))

mServiceArray.Add(New AC_DataBoss.AC_DisplayList(mServiceCode, mServiceID))

'cbServiceCode.Items.Add(m)

Next

cbServiceCode.DataSource = mServiceArray

cbServiceCode.DisplayMember = "LongName"

cbServiceCode.ValueMember = "ShortName"

End Function

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uZ*************@TK2MSFTNGP12.phx.gbl...
Bill,

However, the combobox somehow display the Valuemember instead of
DisplayMember!
What did I do wrong?


Can you show that piece of code frome you,

Cor

Nov 21 '05 #9
Bill,

I think that it is dead simple. You told us that the datasource was tabler
A.
Now I see that your datasource is a complete dataset.

That normally gives only an empty combobox.

cbServiceCode.DataSource = dS.Tables(0)

I stopped with reading when I saw this by the way.

I hope it helps,

Cor
Nov 21 '05 #10
Cor;

Thanks for pointing it out.

I got displaying problem after that, but it was the order and
case-sensitive issue with the column names.

Thanks for your help!

Bill

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Bill,

I think that it is dead simple. You told us that the datasource was tabler
A.
Now I see that your datasource is a complete dataset.

That normally gives only an empty combobox.

cbServiceCode.DataSource = dS.Tables(0)

I stopped with reading when I saw this by the way.

I hope it helps,

Cor

Nov 21 '05 #11
Bill Nguyen wrote:
I got displaying problem after that, but it was the order and
case-sensitive issue with the column names.


sorry, I was away for a bit... glad to see that you got it sorted out...

Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: honeybee | last post by:
How to get the item value from a specific Item Index in the listbox?
2
by: George Addison | last post by:
How do I test for the value of the repeater's item index: SOmething like: Select Case Container.ItemIndex if container.itemindex
2
by: Adam Knight | last post by:
Hi all, I am wanting to display a data lists item index inline in a script. Meaning not from code behind but <%# %> ect. Obviously i can display a dataitem by using: <%#...
0
by: Leonardo Santos-Macias | last post by:
I have a dropdown list that I bind at runtime. It does postback to the server. If I select any item, it will trigger the SelectedIndexChange event. My problem is that it doesn't trigger the...
2
by: B | last post by:
I'm trying to simply build a form with a combo box containing a list of states. I'd like for there to be NO default selected item, but invariably, the first item in the DataSource is being...
0
by: Bob | last post by:
Its often necessary to allow the user to remove a selection from a combox. In my case, most are bound to lookup tables. I suppose I could, in each lookup table create an empty record and have in...
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...
2
by: Thomas E. Nørgaard | last post by:
Hey guys! Does anyone know how to get the value of the highlighted item when the combobox is dropped down and the cursor is hovering over the item? Thanks! Best Regards Thomas
0
by: Bruno Neves Pires Silva | last post by:
Hello, everybody. How can I get the selected item index in a DataGridViewComboBoxCell, in a datagridview?
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.