Value in ListBox.Items.Add

  • Thread starter Thread starter cerebellum
  • Start date Start date
C

cerebellum

Hi,
How do I add items in ListBox in VB.NET with the value;
ListBox.Items.Add("Text") only assign the text instead of the values.

Thnx
 
cerebellum said:
Hi,
How do I add items in ListBox in VB.NET with the value;
ListBox.Items.Add("Text") only assign the text instead of the values.

Thnx

Hi, Cerebellum
Check the item property, e.g.: ListBox.Items.Item(lIdx).ToString

Regards,
Petar Atanasov
http://a-wake.net
 
Hi, Cerebellum
Check the item property, e.g.: ListBox.Items.Item(lIdx).ToString

Regards,
Petar Atanasovhttp://a-wake.net

What I'm trying to do is populate a name as display, but returning
selectedvalue upon click. With ListBox.Items.Add(name) only adds the
display value, not the selected value. isn't ToString is just what is
displayed?
 
cerebellum said:
What I'm trying to do is populate a name as display, but returning
selectedvalue upon click. With ListBox.Items.Add(name) only adds the
display value, not the selected value. isn't ToString is just what is
displayed?

hmm there is obvously something that I miss...

Does the ListBox.SelectedItem contain what you need ?

SelectedItem holds the item,
while SelectedIndex points to it's index in the collection.

OnClick you can capture them both and return, pass, etc. what's needed...

Regards,
Petar Atanasov
http://a-wake.net
 
cerebellum said:
What I'm trying to do is populate a name as display, but returning
selectedvalue upon click. With ListBox.Items.Add(name) only adds the
display value, not the selected value. isn't ToString is just what is
displayed?

hmm,

"...selectedvalue upon click..."
probably there is a misconseption with this property name.
It deals with ValueMember of ListControl not with the actually selected
Item (as you cen see in the Object Browser)...

Regards,
Petar Atanasov
http://a-wake.net
 
hmm,

"...selectedvalue upon click..."
probably there is a misconseption with this property name.
It deals with ValueMember of ListControl not with the actually selected
Item (as you cen see in the Object Browser)...

Regards,
Petar Atanasovhttp://a-wake.net

i want to set the value, not retrieve it. say that i have a table with
the fields userid.string and username.string and i want to put some
records into the table with the displayname: username. so i can handle
events (like click) to the appropriate userid with the SelectedValue
of the list.

I can do this using the data binding the control, but how do i do it
in code?
 
cerebellum said:
i want to set the value, not retrieve it. say that i have a table with
the fields userid.string and username.string and i want to put some
records into the table with the displayname: username. so i can handle
events (like click) to the appropriate userid with the SelectedValue
of the list.

I can do this using the data binding the control, but how do i do it
in code?

I don't see the reason of such approach, still more there is a plethora
of data toys - Dataset, Table, ArrayList, ListControl, etc.

Choose a tool, furnish it, than bind the control - couldn't be more neatly.

Regards,
Petar Atanasov
http://a-wake.net
 
Back
Top