Hello:
I would like to move a ListBoxA to ListBoxB. I tried the code below but its not working. What am I missing?
ListBoxB = ListBoxA;
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
DRISHTY134 reputationPosted May 10, 2010, 4:49 AM EDT
string[] myListItemArray =new string[listBox1.Items.Count];
listBox1.Items.CopyTo(myListItemArray, 0);
listBox2.Items.AddRange(myListItemArray);
Dipa AhujaRank #1,168 · 1.5K reputationPosted May 10, 2010, 4:24 AM EDT
Jaish MathewsRank #225 · 11K reputationPosted May 10, 2010, 5:40 AM EDT
Here's a method using for each
foreach (object obj in listBox1.Items)
{
listBox2.Items.Add(obj);
}
listBox1.Items.Clear();
GustavoRank #1,990 · 732 reputationPosted May 10, 2010, 5:53 AM EDT
Thanks. I knew of the 'for' way of doing it. I thought that maybe there was a way to just move it.
I am learning, so I decided to use the sample from Drishty.
Thanks to all.
Jaish MathewsRank #225 · 11K reputationPosted May 10, 2010, 7:15 AM EDT
I am totally agree with your way of learning
GustavoRank #1,990 · 732 reputationPosted May 10, 2010, 7:24 AM EDT
I usually try to figure it out for 2 hours by myself. I read some documents and surf the net to find the solution. After 2 hours, if I cant find it, then I post.
I have learned so much stuff that you can not find in a book. I have been working on my project for around 4 months. I am hoping by the end of the month I get done with the basics. Then I might spend a month or more, going thru the Forms and Classes and document all the routines.
Write now I am writing a generic Validation routine that is controlled by a table. It pretty cool. I am sure an expert will see flaws in my code...LOL.