|
-
Aug 15th, 2003, 12:15 PM
#1
Thread Starter
Lively Member
This might help someone...
I am new to VB.Net. And for some reason this took me awhile to figure out how to do. I basically have a Listbox being populated by a dataset. Well using the dataview. After it was populated for the selecteditem property of the listbox was something like system.data.datarow
Something Like that.
Here is alittle code to help get the text that is selected in the listbox after populating it with a dataset.
<vbscript>
Dim i As Integer
dim sSelectedText as String
i = lstData.SelectedIndex
sSelectedText = lstData.GetItemText(lstData.SelectedValue)
Call MessageBox.Show(sSelectedText)
</vbscript>
Hope this helps someone. It gave me a headache...but it seems that comes with trying to migrate from vb6 to .net
-
Aug 15th, 2003, 12:41 PM
#2
did this not work then ...
VB Code:
MessageBox.Show(ListBox1.SelectedItem)
cuz that should show you the selected item also.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Aug 15th, 2003, 01:13 PM
#3
Thread Starter
Lively Member
no ....
instead of what was selected it returned.
System.data.datarow
or something like that.
-
Aug 15th, 2003, 01:26 PM
#4
If you set the valuemember property of the listbox to the fieldname of the field you want to show then you can use SelecteValue. Otherwise you can use SelectedItem and cast it to a dataviewrow then pick whatever field you want to show.
PS: The Valuemember and Displaymember properties are case sensitive.
VB Code:
'using valuemember
'as long as the valuemember property is set like this:
ListBox1.ValueMember = "record_Text"
'then this will work
MsgBox(ListBox1.SelectedValue)
'using selecteditem
MsgBox(DirectCast(ListBox1.SelectedItem, Data.DataRowView)("record_Text").ToString)
'this way doesn't matter if valuemember is set you just have to cast
'to a dataviewrow and pick your field
Last edited by Edneeis; Aug 15th, 2003 at 01:32 PM.
-
Aug 15th, 2003, 01:58 PM
#5
Frenzied Member
Originally posted by Edneeis
PS: The Valuemember and Displaymember properties are case sensitive.
A real good point.
Also I expect Edneeis (as a guru) to use MessageBox.Show so that newbies like me learn better syntax of .NET.
Last edited by Lunatic3; Aug 15th, 2003 at 02:13 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 15th, 2003, 02:36 PM
#6
[Insert Blushing Smiley Here]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|