need help with code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

need help with code

ZeroOverRidZeroOverRid Posts: 23Member
[b][red]This message was edited by ZeroOverRid at 2006-2-7 18:9:42[/red][/b][hr]
ok i am trying to take the text from a list box and put it into another list box and then clear the text in the first list box and i have to use a button to do this.

here is the code i got
this is the button code button name is: btn
[code]
private void btnChange_Click(object sender, System.EventArgs e)
{
this.listBox1.Items.CopyTo(this.listBox2.Items);
// this is where i get the error saying i need more arguments and I get stuck here,
// I try msdn.com and i couldn;t find anything that could help me
this.listBox1.Items.Clear();
}


}
[/code]


Comments

  • weiccoweicco Posts: 950Member
    : [b][red]This message was edited by ZeroOverRid at 2006-2-7 18:9:42[/red][/b][hr]
    : ok i am trying to take the text from a list box and put it into another list box and then clear the text in the first list box and i have to use a button to do this.
    :
    : here is the code i got
    : this is the button code button name is: btn
    : [code]
    : private void btnChange_Click(object sender, System.EventArgs e)
    : {
    : this.listBox1.Items.CopyTo(this.listBox2.Items);
    : // this is where i get the error saying i need more arguments and I get stuck here,
    : // I try msdn.com and i couldn;t find anything that could help me
    : this.listBox1.Items.Clear();
    : }
    :
    :
    : }
    : [/code]
    :
    :
    :

    CopyTo takes 2 arguments: destination and offset. You are missing the offset. But that wont work since you can't conect ObjectCollection to object-array. This should work:

    [code]
    listBox2.Items.AddRange(listBox1.Items);
    listBox1.Items.Clear();
    [/code]
Sign In or Register to comment.