-
March 17th, 2010, 06:20 AM
#1
copy listbox item to listbox2
hi,
i want to copy items from my listbox1 to listbox2
here is my code
Code:
private void button1_Click(object sender, EventArgs e)
{
string objSelected = "";
foreach (object sel in listBox1.SelectedItems)
{
objSelected = lstBox1.SelectedItems[3].ToString();
listBox2.Items.Add(objSelected.ToString());
}
}
and my error is always it sees the item selected as datarowview
Code:
System.Data.DataRowView
any advice
thanks!
-
March 17th, 2010, 09:37 AM
#2
Re: copy listbox item to listbox2
You want to copy all of the items from listbox1 to listbox2? In that case, this is the code you should use:
Code:
private void button1_Click(object sender, EventArgs e)
{
//Use this to copy all items
foreach (object item in listBox1.Items)
{
listBox2.Items.Add(item);
}
//Use this to copy selected items
foreach (object item in listBox1.SelectedItems)
{
listBox2.Items.Add(item);
}
}
It's not a bug, it's a feature!
-
March 17th, 2010, 07:58 PM
#3
Re: copy listbox item to listbox2
sorry, i didnt indicate that i want to copy selected items to another listbox
tia
-
March 18th, 2010, 02:33 AM
#4
Re: copy listbox item to listbox2
Well then use the second loop in my last post
It's not a bug, it's a feature!
-
March 18th, 2010, 08:16 PM
#5
Re: copy listbox item to listbox2
but it only outputs System.data.datarowview and not the items itself.
btw, my listview has datasource from a table.
i dont know why it keeps on returning System.data.datarowview.
-
March 18th, 2010, 09:22 PM
#6
Re: copy listbox item to listbox2
So... is it a ListBox or a ListView, as it seemed to change after Foamy's post?
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|