Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.