473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 27768
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

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

Similar topics

4
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through...
3
by: Usenet | last post by:
Hi there, I am quite a novice to MS Access, and I would deeply appreciate help on the following: I have created a list box in a form. I wish for that list box to enter multiple values from table...
10
by: aroraamit81 | last post by:
I have a string like "English,Japanese,Spanish" and a list box which contains say 10 lang. Now I want my List box should come by selected values as the values in string and rest of the values to...
0
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice...
7
by: Aaron Gray | last post by:
I put together the following code to get the href's parameters :- function GetParameters() { var arg = new Object(); var href = document.location.href; if ( href.indexOf( "?") != -1) { var...
6
by: nephish | last post by:
Hey there all. i have been looking to simplify my huge website that i wrote while learning php. now its a spaghetti mess. So, i wanted to simplify it. Now, i see the functionality that defining...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
4
by: Brett Wesoloski | last post by:
I am having a bit of a problem getting the current value of the checkbox list. I have tried using the selected value as I thought that would give me the current value of the check box but it...
2
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.