dataset.selecteditem question

  • Thread starter Thread starter Shannon Ramirez
  • Start date Start date
S

Shannon Ramirez

I'm working with a databound listbox. Data comes up i the list box,
but my problem happens when I go to selected something from that list
box. a listbox.selecteditem returns me the primary key value from the
column specified in the .valuemember. but when I do a
listbox.selectedvalue I don't get anything back. I get this

{System.Data.DataRowView}
[System.Data.DataRowView]: {System.Data.DataRowView}

I tried doing what I've done before when not working on a ce,
selectedvalue.text but that doesn't work on the compact .net

can someone please help me out

thanks
shannon
 
If you have specified DisplayMember and ValueMember, then you can use
SelectedValue property
In any case the SelectedItem property gives you access to the underlying
datarow:

Dim dr as DataRow = CType(listbox.SelectedItem, DataRowView).Row
Dim ID as Integer = CInt(dr.Item("ID")) ' Presuming your dataset has a filed
called ID
 
thanks for the info. Here is what I was doing.

Dim objds1 As New DataSet
objds1 = objService.GetEmployeeList

With Me.ListBox2
.DataSource = objds1.Tables("EmployeeList")
.DisplayMember = "vcFirstName"
.ValueMember = "intTblEmployeeId"
End With

does that makes sense that selectdvalue would not show up.

I used this based off what you gave me.
Dim dr As DataRow = CType(Me.ListBox2.SelectedItem, DataRowView).Row
Dim value As String = CType(dr.Item("vcFirstName"), String)
and that does give me the data back.. now on to anotehr problem with
this. I'm using Listbox2_selectedindexchanged. when the form goes to
load, it hits this indexchanged once for each row. Is this expected
behavior. I don't want it to be looking at the change in index until
someone clicks on the listbox.

hope you are willing to give a little more info. What you gave me
will work, i just don't understand why the selectedvalue didn't

If you have specified DisplayMember and ValueMember, then you can use
SelectedValue property
In any case the SelectedItem property gives you access to the underlying
datarow:

Dim dr as DataRow = CType(listbox.SelectedItem, DataRowView).Row
Dim ID as Integer = CInt(dr.Item("ID")) ' Presuming your dataset has a filed
called ID

Shannon Ramirez said:
I'm working with a databound listbox. Data comes up i the list box,
but my problem happens when I go to selected something from that list
box. a listbox.selecteditem returns me the primary key value from the
column specified in the .valuemember. but when I do a
listbox.selectedvalue I don't get anything back. I get this

{System.Data.DataRowView}
[System.Data.DataRowView]: {System.Data.DataRowView}

I tried doing what I've done before when not working on a ce,
selectedvalue.text but that doesn't work on the compact .net

can someone please help me out

thanks
shannon
 
Back
Top