472,122 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

Getting multiple values from a List box in C#

69
Hello all...

I have a list box that is pulling it's data from a sql table. I have its selection mode set to multiextended.

I have the display member for each item set to the Name field from the sql table and the value member for each item set to the ID field from the sql table.

When I select multiple items from the list, how do I get the multiple values? I am able to get the text of one item by using the listboxname.Text but I don't know how to get each value that has been selected all at once.

Any help will be greatly appreciated.
Jul 5 '07 #1
7 27621
kenobewan
4,871 Expert 4TB
Seem to remember doing this once using an array. HTH.
Jul 6 '07 #2
dip_developer
648 Expert 512MB
Hello all...

I have a list box that is pulling it's data from a sql table. I have its selection mode set to multiextended.

I have the display member for each item set to the Name field from the sql table and the value member for each item set to the ID field from the sql table.

When I select multiple items from the list, how do I get the multiple values? I am able to get the text of one item by using the listboxname.Text but I don't know how to get each value that has been selected all at once.

Any help will be greatly appreciated.
you can use the SelectedItems property of the listbox.........
It gets a collection of currently selected items in the listbox......

you can have the items like..............

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim lstItem1 As String=ListBox1.SelectedItems.Item(0)
  3.  
is this the answer you are looking for?? let me know...
Jul 6 '07 #3
narpet
69
you can use the SelectedItems property of the listbox.........
It gets a collection of currently selected items in the listbox......

you can have the items like..............

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim lstItem1 As String=ListBox1.SelectedItems.Item(0)
  3.  
is this the answer you are looking for?? let me know...
Do you know how I would do this in C# ?

Thanks
Jul 10 '07 #4
TRScheel
638 Expert 512MB
Do you know how I would do this in C# ?

Thanks

Expand|Select|Wrap|Line Numbers
  1. Dim lstItem1 As String=ListBox1.SelectedItems.Item(0)
  2.  
to C#:

Expand|Select|Wrap|Line Numbers
  1. string lstItem1 = ListBox1.SelectedItems.Item(0);
  2.  
Jul 10 '07 #5
narpet
69
That's exactly what I needed.

Thanks very much!
Jul 10 '07 #6
Hi none posted cure.. for narpet's problem

There is a (perfect cure..) sample code behind

function that is a click event handler of a button(Button1)
that will retrieve multi selected value from listbox(ListBox1)
control to a label(Label1) control

protected void Button1_Click(object sender, EventArgs e)
{
foreach(int i in ListBox1.GetSelectedIndices())
{
Label1.Text =Label1.Text+" "+ListBox1.Items[i].Value;
}
}
Aug 4 '07 #7
narpet
69
Thanks very much... I will try this as soon as possible.
Aug 10 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Usenet | last post: by
10 posts views Thread by aroraamit81 | last post: by
7 posts views Thread by Aaron Gray | last post: by
6 posts views Thread by nephish | last post: by
8 posts views Thread by aleksandar.ristovski | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.