473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Multiple selection in ListBox

I have a string like "English,Japane se,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 be unselected.

But what I am getting is the last value selected (Spanish in this
case).

Any help.......
Regards,
Amit

Feb 27 '06 #1
10 1857
Amit,

Loop through each item and check if each one is selected.

For Each ListBoxItem As ListItem In MyListBox.Items

If ListBoxItem.Sel ected Then

'---This item is selected do something with it

End If

Next
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<ar*********@gm ail.com> wrote in message
news:11******** *************@p 10g2000cwp.goog legroups.com...
I have a string like "English,Japane se,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 be unselected.

But what I am getting is the last value selected (Spanish in this
case).

Any help.......
Regards,
Amit

Feb 27 '06 #2
char[] splitter = {','};
string
[]lang=ds.Tables[0].Rows[0]["USER_LANG_ ID"].ToString().Spl it(splitter);

foreach(string i in lang)
{
for(int j=0;j<lstLang.R ows;j++)
{
if(lstLang.Item s[j].Text==i)
{
lstLang.Selecte dIndex=j;
Response.Write( i);
}
}
}

This is the code I am using... but it does not work....

Pls see.....

Feb 27 '06 #3
Hi Amit,
Have you changed selection mode from single to multiple??

Feb 27 '06 #4
To start with try simplifying the code.

You don't even need to compare the entries with the dataset because the
listbox already has the entiries in it:

for (int j = 0; j < myListBox.Rows; j++)

{

if(myListBox.It ems[j].Selected)

{

Response.Write( myListBox.Items[j].Text;

}

}

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<ar*********@gm ail.com> wrote in message
news:11******** **************@ j33g2000cwa.goo glegroups.com.. .
char[] splitter = {','};
string
[]lang=ds.Tables[0].Rows[0]["USER_LANG_ ID"].ToString().Spl it(splitter);

foreach(string i in lang)
{
for(int j=0;j<lstLang.R ows;j++)
{
if(lstLang.Item s[j].Text==i)
{
lstLang.Selecte dIndex=j;
Response.Write( i);
}
}
}

This is the code I am using... but it does not work....

Pls see.....

Feb 27 '06 #5
Yeah I have done it......

Feb 27 '06 #6
I guess its me who is unable to make u understand.....

Well the databse field tells u the language list (Comma Seprated) which
needs to be selected. So I have to get the values from the databse
itself.....

Feb 27 '06 #7
Ok, you're trying to select each item in the list based on the dataset. Now
I've got you.

Very similar. First you will certainly have a problem if the text doesn't
match exactly. Strings matching is case sensitive remember. So make certain
that your data and the entries in the list box are exactly the same. Or use
a .ToLower to make certain.

Next your real problem is that you're using SelectedIndex. That keeps
changing the selected index to a single item. It automatically deselects any
other. You have to set each item to selected seperately like this:

foreach(string i in lang)
{
for(int j=0;j<lstLang.R ows;j++)
{
if(lstLang.Item s[j].Text==i)
{
lstLang.Items[j].Selected = True;
}
}
}

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<ar*********@gm ail.com> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.com...
I guess its me who is unable to make u understand.....

Well the databse field tells u the language list (Comma Seprated) which
needs to be selected. So I have to get the values from the databse
itself.....

Feb 27 '06 #8
Well Mate I tried it but, did nt work either......... ..

Feb 27 '06 #9
No NO No No No,
IT HAS WORKED......... ............... ............... ....

Thnx a lot Mate........... ............... ............... ............... .

Feb 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2019
by: Polar | last post by:
I have a listbox with 5 options. I have set it up to be able to choise more than one option. What I need to know is how to get all the selection into the one string that is stored in the DB It is easy to get the first selected option to post into the DB. Thanks for your thoughts and aideas.
1
3553
by: theoryboy | last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist using a control-click. I've bound control-click to a function that uses selection_set to add to the selection, but it doesn't seem to work. Only the last clicked item appears selected (highlighted) in the display and the return from info_selection only ever contains the...
0
3490
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or...
2
2552
by: DK | last post by:
Hello everybody ! I need little help from Your side. I have form called Form2, and ListBox called List 20. Property of List 20 allow multiple selection. Also I have query called Distribution as mail merge source.I need to control query Distribution to send letters to people selected in List 20. When I use List20 control without multiple...
0
2586
by: AK | last post by:
Hello, Listbox mulitselect property is set to true (extended). I am trying to implement drag and drop feature for a listbox. The drag & drop is done in the mouse move event (DoDragdrop function is called in mouse move event). I am facing two problems: 1. First is that when shift key is pressed and left mouse button is down. The listbox...
2
2264
by: Peter | last post by:
Hello! Please, could anyone tell, is it possible to set multiple items to be selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list control already? Now I manage to set only one item to be selected during page load, but there is need to multiple items could be selected for the...
0
1356
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual Studio Webform. I wish obtain various records from My_Store_Procedure and fill dataset.
5
3517
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all selected items of that listbox and display it. can anyone help? Thanks
2
3110
by: Dolorous Edd | last post by:
Hi, for a program I'm working on I need to be able to drag multiple files between Windows Explorer and a ListBox, in both directions. Implementing the "drag in" was pretty easy, but I can't find a way to export more than on item at time. The ideal result would be to be able to drag the selected files, but as soon as I click on the LB to...
2
5112
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 1st listbox(PalletNo). Now I want to select miltiple values from that 1st listbox(PalletNo). and based upon this selection from 1st...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.