Home > DeveloperSection > Forums > How to create a copy of the items in a domainupdown C#
jacob rasel
jacob rasel

Total Post:88

Posted on    December-23-2013 3:26 AM

 C# C# 

 1 Reply(s)
 1329  View(s)
Rate this:

I was able to copy decimal values from a numericUpDown box fine, but when I try to copy items from a DomainUpDown box with a predefined collection of items to a new DomainUpDown box I run into problems since I think it may be an array of strings. Here is what I have so far:

private DomainUpDown sentNUD2;

private void domainUpDown_Click(object sender, EventArgs e)


    formPopUpData2 newForm = new formPopUpData2();

    this.sentNUD2 = (DomainUpDown)sender;

    DomainUpDown copiedNUD = new DomainUpDown();

    for (int i = 0; i <= this.sentNUD2.Items.Count-1; i++)


        copiedNUD.Items[i] = this.sentNUD2.Items[i];


My code above is similar to what I did with the numeric boxes, but the addition is the for loop for the array. I keep getting an out of bounds error. Is there an easier way to copy items from one DomainUpDown to another? Am I on the right track? Any help is appreciated.

Thank you.

Pravesh Singh

Total Post:412

Posted on    December-23-2013 5:16 AM

Hi Jacob,

When this code runs, copiedNUD.Items has count of zero. You need to use an Add method on the collection:

copiedNUD.Items.Add(this.sentNUD2.Items[i]); //fixed naming

Don't want to miss updates? Please click the below button!

Follow MindStick