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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
DRISHTYPosted May 10, 2010, 8:49 AM
string[] myListItemArray =new string[listBox1.Items.Count];
listBox1.Items.CopyTo(myListItemArray, 0);
listBox2.Items.AddRange(myListItemArray);
GustavoPosted May 10, 2010, 11:24 AM
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.
Jaish MathewsPosted May 10, 2010, 11:15 AM
I am totally agree with your way of learning
GustavoPosted May 10, 2010, 9:53 AM
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 MathewsPosted May 10, 2010, 9:40 AM
Here's a method using for each
foreach (object obj in listBox1.Items)
{
listBox2.Items.Add(obj);
}
listBox1.Items.Clear();
Dipa AhujaPosted May 10, 2010, 8:24 AM