I'm having a bit of problems with my listbox..
Based on the item selected in the listbox,the corresponding in stock number and price number are meant to appear in the textboxes, this functions fine when it was databinded with VB's inbuilt databinding (clicking the listbox and using databound items etc). However I had to remake the project and doing this does not work now as the databinding built in doesn't let me change the connection string from |DataDirectory|.
Loading the listbox manually using a code to populate a dataset with the ProductName column from my ProductTbl and setting that as the datasource and the ProductName as listbox DisplayMember and Value member does make them appear in thelsitbox however clicking them doesn't trigger the corresponding quantity etc... (I was opening the connection and loading the dataset/listbox then closing connection on the form load event, deleted the code so no example)
Here's my code corresponding to get the quantity and price...any ideas/help please? using the selectedvalue worked for it when it was bound with vb's inbuilt function however neither selectedvalue,valuememebr or displaymember work to get the corresponding values to show when populating it myself with an sql statement, any ideas/help?
Based on the item selected in the listbox,the corresponding in stock number and price number are meant to appear in the textboxes, this functions fine when it was databinded with VB's inbuilt databinding (clicking the listbox and using databound items etc). However I had to remake the project and doing this does not work now as the databinding built in doesn't let me change the connection string from |DataDirectory|.
Loading the listbox manually using a code to populate a dataset with the ProductName column from my ProductTbl and setting that as the datasource and the ProductName as listbox DisplayMember and Value member does make them appear in thelsitbox however clicking them doesn't trigger the corresponding quantity etc... (I was opening the connection and loading the dataset/listbox then closing connection on the form load event, deleted the code so no example)
Here's my code corresponding to get the quantity and price...any ideas/help please? using the selectedvalue worked for it when it was bound with vb's inbuilt function however neither selectedvalue,valuememebr or displaymember work to get the corresponding values to show when populating it myself with an sql statement, any ideas/help?
VB.NET:
Private Sub listProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listProducts.SelectedIndexChanged
Try
con.Open()
'sql statement selecting product price and quantity for the selected productname from listProducts(listbox)
sql = "SELECT ProductPrice,ProductQuantity FROM ProductTbl WHERE ProductName='" & listProducts.SelectedValue & "'"
da = New OleDb.OleDbDataAdapter(sql, con)
'fil "PRODUCT" dataset using data adapter
da.Fill(ds, "PRODUCT")
'fill appropriate textboxes with table data
txtCurrentQuantity.Text = ds.Tables("PRODUCT").Rows(0).Item(1)
txtPrice.Text = ds.Tables("PRODUCT").Rows(0).Item(0)
ds.Clear()
con.Close()
Catch ex As Exception
End Try
End Sub