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

Storing and then retrieving ValueMember info from a list or combo box

Dim intCurID As Integer *** outside of code and available to all
***

Dim strConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Databases\ClientAppDB.mdb;"
Dim objConnection As New OleDbConnection(strConnectionString)
Dim strSQl As String = "SELECT CLIENTID, FIRSTNAME, LASTNAME
FROM CLIENTS ORDER BY LASTNAME"
Dim objCommand As New OleDbCommand(strSQl, objConnection)
Dim objDataReader As OleDbDataReader
Try
objConnection.Open()
objDataReader = objCommand.ExecuteReader *** is this
correct ***

While objDataReader.Read()
Me.ListBox1.Items().Add(objDataReader.Item(2) & ", "
& objDataReader.Item(1))
Me.ListBox1.ValueMember = objDataReader.Item(0)
End While

*** All this code works perfectly and the ValueMembers show as
correct when looping throught the data reader ***
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged

intCurID = Me.ListBox1.SelectedValue
End Sub

*** Here I want get the current selected Value but ***
*** all it show is zero ***
*** Am I going about this the wrong way? I want to use ***
*** code and not the Properties on the form due to a ***
*** calculated SQL statment I use for the listbox ***

*** Thanks for any help ***

Jul 28 '05 #1
2 1275
Tom,

The best thing you can do is to put in top of your program or in the VS
properties

Option Strict On

Probably you get the result by
intCurID = Cint(Me.ListBox1.SelectedValue)

I hope this helps,

Cor
Jul 29 '05 #2
Cor..........Thanks for your help. When I put Option strict on I got a
ton of errors pertaining to the data objects. I changed the option to
Explicit. Your last line of code did not work. It still showed the
selected value as zero. Thanks anyway
Tom

Jul 31 '05 #3

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

Similar topics

0
by: Dianna K | last post by:
I have a combo box which is set up as such: Me.cboGenre.DataSource = Ds.Tables("Genre") Me.cboGenre.ValueMember = "genre_id" Me.cboGenre.DisplayMember = "genre_description" The above loads...
5
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
4
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of...
6
by: Shannan Casteel via AccessMonster.com | last post by:
I'll explain as well as possible...not an experienced user...but learning. I am working on a database for different kinds of problems with machines. A user will be able to select a problem...
3
by: jay | last post by:
I have a structure: public struct DATA_PAIR { public int ID; public string Value; public DATA_PAIR(int id, string val) { this.ID = id;
3
by: Tony Maresca | last post by:
I am binding a combo box to an ArrayList of objects with a property called "Name" that is assigned to DisplayMember. How can I have the SelectedValue of the combo return the instance of the...
2
by: travlintom | last post by:
Dim intCurID As Integer *** outside of code and available to all *** Dim strConnectionString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Databases\ClientAppDB.mdb;"...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
10
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.