PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 1.00 average.

dataset.selecteditem question

 
 
Shannon Ramirez
Guest
Posts: n/a
 
      17th Mar 2004
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
 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      17th Mar 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Shannon Ramirez
Guest
Posts: n/a
 
      17th Mar 2004
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

On Wed, 17 Mar 2004 12:53:56 -0800, "Alex Feinman [MVP]"
<(E-Mail Removed)> wrote:

>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" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C#1.1 ListView CheckBox selecteditem question Jason Huang Microsoft C# .NET 0 6th Sep 2007 04:10 AM
SelectedItem.Value Martyn Fewtrell Microsoft ASP .NET 4 24th May 2005 04:44 PM
DropDown1.SelectedItem.Value....... Lasse Edsvik Microsoft ASP .NET 5 4th Oct 2004 11:51 AM
Listbox selecteditem - newbie question Bill Nguyen Microsoft VB .NET 2 28th Aug 2004 12:57 AM
Question: Dropdownlist SelectedItem always returns 1st value! VB Programmer Microsoft ASP .NET 4 29th Jan 2004 02:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.