Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which Listbox attribute

Status
Not open for further replies.

tmryan

Programmer
Dec 22, 2000
73
US
I have a listbox (Datasource is an Access DB, Displaymember is a column) and I want to capture the user selection of the listbox. I have an event module "SelectedValueChanged" where I'm trying to capture the text of the item selected, but I can't figure out which attribute that is. When I capture SelectedValue - I get "System.Data.DataRowView". Which attribute do I want?

Thanks
Tim Ryan Tim Ryan
PROGRESS Developer
 
Hey there Tim
What you want is the listbox1.selectedItem property. This will give you the text that is displayed in the box. However, keep in mind that if your list box supports multiple selections you may have a problem. In this case the selectedItem property holds the lowest selected index.
eg.
Test
Stuff
Test1

You select Stuff. selectedIndex now holds "Stuff"
You also select Test1. selectedIndex still holds "Stuff"
You also select Test. selectedIndex now will hold "Test"

Just keep that in mind when your are designing your form. Should you want to do something with this you may want to look into using the seletedItems property.

HTH That'l do donkey, that'l do
[bravo]
 
Zarcom,

Thanks. I've tried that though. My listbox is called lbTopicList. On SelectedValueChanged of lbTopicList I have a MsgBox to see what I'm selecting (debugging). I display lbTopicList.SlectedItem.ToString - what I get is "System.Data.DataRowView" in my message box. I've set the following properties for the listbox:
DataSource = DseQkb1.eQkb (A dataset)
Displaymember = Topic (which is a column in the DB).

Typical values in the listbox are:
Raw vs Mapped Data
Required Programs
Startup Script
....

These are loaded on form_load from the DB. This is a knowledgebase I'm creating. I want the user to select an item from the listbox - then display the associated information in a textbox that is also on the form.

Thanks
Tim Tim Ryan
PROGRESS Developer
 
A little more explanation of what I'm trying to do. I have an Access DB called eQkb that has 1 table called eQkb, that has two fields. The fields are called Topic and Description (both text). On my form I have a listbox called lbTopicList and a textbox called tbDescription. The listbox loads from the values in eQkb.Topic - no problem. When a user selects and item in lbTopicList (multiselect is no), I want the corresponding eQkb.Description to display in tbDescription. Would be easy to do in Progress (my main language) - but since I'm new to VB .Net - I haven't figured it out yet.

Thanks
Tim Tim Ryan
PROGRESS Developer
 
This is getting frustrating. When I MsgBox(lbTopicList.SlectedIndex) - I get the appropriate integer relative to the item I select in the ListBox. When I MsgBox(lbTopicList.SelectedValue) I get an error message that states:

An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll

Additional information: Argument 'Prompt' cannot be converted to type 'String'.

How do I capture the text of the value selected in the listbox?

Thanks
Tim Tim Ryan
PROGRESS Developer
 
Can you post some code and tell us where it is failing? That'l do donkey, that'l do
[bravo]
 
Thanks.

As I mentioned before - my listbox name is lbTopicList. The datasource property is set to the DB/table, the DisplayMember is Topic (which is the field I want). The event code is:
Private Sub lbTopicList_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbTopicList.SelectedValueChanged
MsgBox(lbTopicList.SelectedValue)
End Sub

When I display the SelectedIndex - it seems to work correctly. When I display the SelectedValue - well you know. I know I'm new to VB .Net, but this would take me about 10 seconds in my native language (Progress). What I want to do after I capture the selectedvalue is select the correct record from the DB using eQkb.Topic = lbTopicList.SelectedValue. I haven't figured out how to do that either. In Progress it would be "Find First eQkb NO-LOCK WHERE eQkb.Topic = lbTopicList:SCREEN-VALUE".

Thanks Again
Tim Tim Ryan
PROGRESS Developer
 
Thanks.

As I mentioned before - my listbox name is lbTopicList. The datasource property is set to the DB/table, the DisplayMember is Topic (which is the field I want). The event code is:
Private Sub lbTopicList_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbTopicList.SelectedValueChanged
MsgBox(lbTopicList.SelectedValue)
End Sub

When I display the SelectedIndex - it seems to work correctly. When I display the SelectedValue - well you know. I know I'm new to VB .Net, but this would take me about 10 seconds in my native language (Progress). What I want to do after I capture the selectedvalue is select the correct record from the DB using eQkb.Topic = lbTopicList.SelectedValue. I haven't figured out how to do that either. In Progress it would be "Find First eQkb NO-LOCK WHERE eQkb.Topic = lbTopicList:SCREEN-VALUE".

Thanks Again
Tim Tim Ryan
PROGRESS Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top