Listbox Question

  • Thread starter Thread starter Ed Bick
  • Start date Start date
E

Ed Bick

I added items to a listbox as follows:

Dim datDrivers As New SqlConnection(SQL_CONNECTION_CB)
Dim adpDrivers As New
SqlDataAdapter(MySelectStatement,datDrivers)
adpDrivers.Fill(DriverData, DRIVER_TABLE_NAME)
lstDrivers.DataSource = DriverData.Tables(DRIVER_TABLE_NAME)
lstDrivers.DisplayMember = "Name"
lstDrivers.ValueMember = "DriverID"

I am trying to retrieve the value assigned by this

lstDrivers.ValueMember = "DriverID"

By using a statement like this

Dim strDriverID As String = lstDrivers.SelectedItem.ToString

But all I'm getting is this

System.Data.DataRowView (the value displayed in watches for strDriverID)

What am I doing wrong?
 
Hi,


Dim drv as DataRowView = lstDrivers.SelectedItem
Dim strDriverID As String = drv("DriverID")

Ken
 
Ed Bick said:
I added items to a listbox as follows:

Dim datDrivers As New SqlConnection(SQL_CONNECTION_CB)
Dim adpDrivers As New
SqlDataAdapter(MySelectStatement,datDrivers)
adpDrivers.Fill(DriverData, DRIVER_TABLE_NAME)
lstDrivers.DataSource =
DriverData.Tables(DRIVER_TABLE_NAME) lstDrivers.DisplayMember =
"Name"
lstDrivers.ValueMember = "DriverID"

I am trying to retrieve the value assigned by this

lstDrivers.ValueMember = "DriverID"

By using a statement like this

Dim strDriverID As String =
lstDrivers.SelectedItem.ToString

But all I'm getting is this

System.Data.DataRowView (the value displayed in watches for
strDriverID)

What am I doing wrong?

Untested: Use lstDrivers.SelectedValue
 
Hi Ed,

Does this do it?
Dim strDriverID As String = lstDrivers.SelectedItem.ToString
Dim strDriverId as String = lstDrivers.SelectedValue.ToString,

I hope this helps?

Cor
 
Back
Top