473,772 Members | 3,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I move all items in a listbox to another listbox

Hi All,

On my form, I have 2 listboxes that get populated with the correct items.
I have 4 buttons between the 2 boxes. The first 2 buttons are used to move
the selected item
back and forth between the boxes. That works fine.

The last 2 are used to move all the listbox items (whether they're selected
or not) that are in 1 box over to the other box.
After the move, I want the other box to be empty. I am calling clear() and
that works fine.
I am having trouble here and need help.

I have tried things like:
listbox1.items. addRange(listbo x2.items)
listbox2.items. clear()

I have tried a couple of other things with no success.
I'm sort of a newbie, but I should be able to do this and I'm probably
making it much harder than it has to be.
Any help on how to do this would be greatly appreciated.

Remove the 'nospam' for email or send to ks*******@yahoo .com
Nov 18 '05 #1
1 1594
Try something list this (untested)

foreach(Listite m li in lstSrc)
{
lstDest.Items.A dd( new ListItem(li.Tex t,Li.Value));
lstDest.Items.R emove(li);
}
"kent" <ks*******@nosp am.comcast.net> wrote in message
news:Y_******** ************@co mcast.com...
Hi All,

On my form, I have 2 listboxes that get populated with the correct items.
I have 4 buttons between the 2 boxes. The first 2 buttons are used to move the selected item
back and forth between the boxes. That works fine.

The last 2 are used to move all the listbox items (whether they're selected or not) that are in 1 box over to the other box.
After the move, I want the other box to be empty. I am calling clear() and
that works fine.
I am having trouble here and need help.

I have tried things like:
listbox1.items. addRange(listbo x2.items)
listbox2.items. clear()

I have tried a couple of other things with no success.
I'm sort of a newbie, but I should be able to do this and I'm probably
making it much harder than it has to be.
Any help on how to do this would be greatly appreciated.

Remove the 'nospam' for email or send to ks*******@yahoo .com

Nov 18 '05 #2

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

Similar topics

1
298
by: Job Lot | last post by:
I have worked out how to move items in ListBox when it is populated using Items collection, but it doesn't seems to work when the ListBox is bound to a DataSource. How can i move items when ListBox is populated using DataSource property?
7
2041
by: Byron | last post by:
I'm looking for a way to deny a move from the current listbox item. For instance, if the user is editing the record associated with the current listbox item I want to deny a move within the listbox until they have saved the changes. Is there any way to deny a move from the current item so the SelectedIndexChanged event never fires no matter move the movement was attempted? Whether the user uses the cursor keys or mouse to try and leave...
14
18753
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe is that as more and more are added, population of the list box takes longer and longer. ie the first 10th of the item set are added much much quicker than the last 10th. THis occurs with about 40,000 listbox items. My worry is the listbox may...
1
2947
by: anjupt | last post by:
Hi, I have 2 listboxes with data fetched from database so for both the listboxes datasource is set .i tried to move data from one listbox to another listbox but Error"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Cannot modify the Items collection when the DataSource property is set. " comes up .how can i move data from one listbox to another listbox Thank you
4
1671
by: mikkoO8 | last post by:
hi. im actually making a desktop cleaner that can move the files and icons to a folder inside the listview box. i can make the listview box filled with files contains at the desktop and i can make a new folder which suppose to be move the files on that folder i have 3 problems: 1. is how to get last access time of the FILE and put it column2 of the listview 2. i want to view that are unused icon and document last week, 2weeks, 1month...
4
4634
by: bogdan | last post by:
Hi, I have two listboxes on a page and need to move items between them - using buttons (e.g. "<<" ">>"). Can this be done on a client side in asp.net? I'd like to avoid hitting the server on every add/remove. Thanks, Bogdan
2
4416
by: erbear | last post by:
Hi all, I am new to VB, and I am having some troubles. I have a listbox that when you click on the item it displays a picture in a picture box and a message in a label. It works fine when an item is manually selected, but I want forward and back buttons that will do this. It works once but it doesn't highlight the new item in the listbox, so it gets stuck. I can't use a loop either. Any help is greatly appreciated. See code below: ...
2
4436
by: vinod allapu | last post by:
hi all, i am trying to generate a report, iam using sql server 2000 and Asp.net 2.0. First to select the columns iam using the list box... as we can order by the query result from the selected columns only, i want to use another list box which contains only selected columns.. 1. Iam filling the columns names required into the listbox it is selecting the columns in the select statement to generate report. 2....
5
5682
by: amandab116 | last post by:
I'm having a hard time figuring out how to move items between a left and right listbox server-side. I have a populated listbox from the database on the left and I'm trying to add items to the box on the right and save those values to the database. Can anyone help me? I've searched everywhere and haven't found any code that's helpful! protected void Submit_Click(object sender, EventArgs e) { //foreach (ListItem item in...
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
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.