Le Vo Quang

Le Vo Quang

  • NA
  • 3
  • 0

How to stop code generator in designer in this case

Sep 1 2009 2:58 AM
I am creating a custom control derived from ComboBox. I add some items to custom control in constructor of control.

// this code is sample
public MyCustomControl
{
this.Items.Add("test1");
this.Items.Add("test2");
}

When I drag this custom control to my form, designer auto-generate the code:

// this code in Form1.Designer.cs
this.mycustomControls.Items.AddRange(new object[] {
            "test1",
            "test2"});

When this custom control display on Form1, will have 4 items:
test1
test2
test1
test2

This problem cause duplication.

Please help me how to solve this problem, I don't want designer auto-generate these codes. Thanks.

Answers (1)