cokedev Posted January 6, 2004 Posted January 6, 2004 OK, I put my database info in a listbox....I would like to be able to select the item and get the displaymember and valuemember info from it. It seems that all i can retrieve is an index number, and if that is all that i can get then what is a good way i could go about using the index # to retrieve access to the data. :confused: ------------------------------------------------------ Dim dc As New OleDb.OleDbConnection(strProvider) dc.Open() Dim strSQL As String = "SELECT * FROM Discreps WHERE Job_ID='0'" Dim mydc As New OleDb.OleDbCommand(strSQL, dc) Dim myadp As New OleDb.OleDbDataAdapter(mydc) dsJobDiscreps.Clear() myadp.Fill(dsJobDiscreps) dc.Close() lstDesc.DataSource = dsJobDiscreps.Tables(0) lstDesc.DisplayMember = "Discrep_ID" lstDesc.ValueMember = "JobDiscrep_ID" ----------------------------------------------------- Thank for the help in advance. I just think I have had way too much Dr. Pepper this morning :D Quote
AlexCode Posted January 7, 2004 Posted January 7, 2004 Use the SelectedItem and the SelectedValue to retrieve the info you want... You probably have tryed this but it didn't give you anything you could use... It's because of a bug on the ListBox that gives you a DataRowView object instead of the proper data... This can be overcomed changing the order of the lines you use to set the binding on the ListBox. Change the last 3 lines of your code to this and tell me if it fixed it. lstDesc.DisplayMember = "Discrep_ID" lstDesc.ValueMember = "JobDiscrep_ID" lstDesc.DataSource = dsJobDiscreps.Tables(0) Note that I just changed the position/order of the lines... Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
AlexCode Posted January 7, 2004 Posted January 7, 2004 There's no retional explanation for this... Anything else feel free to ask ... Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
cokedev Posted January 7, 2004 Author Posted January 7, 2004 Can I set myclass to MemberValue like lstDesc.MemberValue = myclass mystring = lstDesc.SelectedValue.id Is this valid? Quote
AlexCode Posted January 7, 2004 Posted January 7, 2004 What is that MemberValue?? ValueMember? ValueMember its the column name on the table that you want to bind to... I'm not quite understanding your point... sorry... Try to explain a little better, ok? Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
cokedev Posted January 7, 2004 Author Posted January 7, 2004 nm it works with the databinding....i think i'll just keep it simple right now....I really do appreciate the help Quote
AlexCode Posted January 7, 2004 Posted January 7, 2004 :) ok... If you want to mess the code all up... count with me :D !! Alex :D Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.