Output from ComboBox

I need to get a class from ComboBox and change its Items property. Here is my code:

public class MyComboBox2 : ComboBox
    private MyObjectCollection MyItems;

    public MyComboBox2()
        MyItems = new MyObjectCollection(this);

    //new public ComboBox.ObjectCollection Items
    new public MyObjectCollection Items
        get {
            return MyItems;


public class MyObjectCollection : ComboBox.ObjectCollection
    public MyObjectCollection(ComboBox Owner) : base(Owner)


    new public int Add(Object j)
        return 0;



As you can see, I am creating a new class MyComboBox2

derived from ComboBox

. This class is expected to have a New Items property that will be of type MyObjectCollection

, not ComboBox.ObjectCollection

. I have a comboBox named myComboBox21

in a type form MyComboBox2

. When I want to add a new object to my ComboBox, I would execute the code like this: myComboBox21.Items.Add("text");

In this case, I complete the method Add


I executed myself. However, the ComboBox on the form does not contain the "text" value. I am attaching a screenshot of the debugger showing the ComboBox values. myComboBox21

contains a Items

Property (which contains the "text" as shown in the screenshot "2.png") and it contains base.Items

(which does not contain the "text" as shown in the "1.png") So apparentlymyComboBox21

contains its own propertyItems

(which I can insert) and its base class property Items

which is displayed on the windows form. What can I do to successfully add my own method to the comboBox? Since my ComboBox has 2 Items properties, can I specify which Items property values ​​should be displayed in the ComboBox? enter image description hereenter image description hereenter image description here


source to share

1 answer

Just by looking at the code very quickly:

The original index of the object is declared as

     virtual Object this[int index] {...}


Can a new keyword be exchanged by overriding in your implementation to make the runtime the selected code?



All Articles