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!

HELP: ListBox problem 1

Status
Not open for further replies.

uhu

IS-IT--Management
May 21, 2003
40
NZ
Hi,

I have a listbox which is populated with values from DataSet:

OdbcDataAdapter1.Fill(ds)
ListBox2.DataSource = ds.Tables(0)
ListBox2.DisplayMember = "Store"

It displays fine in the form, but when I tried to execute this code:

TextBox1.Text = ListBox1.SelectedItem

VB produces this error :

An unhandled exception of type 'System.ArgumentException' occurred in microsoft.visualbasic.dll
Additional information: Argument 'Prompt' cannot be converted to type 'String'.

Please help.. thanx in advance

vito
 
Textbox1.text=lisbox1.selecteditem.tostring()

or

textbox1.text=cstr(listbox1.selecteditem)


Sweep
...if it works dont mess with it
 
thanx, problem solved

This is what I did:

TextBox1.Text = ListBox1.SelectedItem(0)

:)
 
Uhu,

I found this recently and it helped me out alot. However, I don't know why it works. Could you explain? I am new to VB.NET and I am having a lot of trouble learning about ADO.NET and databinding and such.

Thanks,

Elena
 
for "uhu" most recent post Elena:

the listbox1.selecteditem is not 1 selected item, it is the array of selected items and since the default settings allows only a single selection at one time you can just acess the same index of 0 (always the first index in an array)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top