Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
Adding ButtonRight in a combo that inherits from UltraCombo does not seem to be working!
posted

In my case I have inherited from UltraCombo and named it comboBase and then inherits all other combos, for example combo1, from comboBase.  Everything works as expected! However, now I want to add ButtonRight to combo1 but it is not adding it.  I then add ButtonRight to comboBase, hoping that I can hide the right button in some child combos in case I do not need the RightButton but it adds two ButtonRight when I add only one! 

I first need to know if it is possible to add ButtonRight to combo1 that inherits from comboBase. If it is not possible, I need to know why it adds two ButtonRight to combo1 when I add only 1 combo to comboBase and how to hide the ButtonRight in combo1!

 

I have added a project as an example.

 

Thank you

WindowsFormsApplication10.zip
Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Alex,

    The ButtonsRight collection is public and it gets serialized by the designer. So if you add a button to the designer in the combo1 class, then when you open the Form designer, the form designer will see the button and serialize it. The next time you open the designer, it will get added by both the combo1 designer code and the Form code.

    This is basically one of the limitations of visual inheritance in Visual Studio. It will happen with any control that has a public collection. You can duplicate the same sort of behavior using Nodes in a TreeView control, for example.

    I think you can get around this by not adding the button through the designer, but instead, add it in code in the OnCreateControl method. This way it only gets called when the control is created the first time.


        public partial class UserControl1 :  Infragistics.Win.UltraWinGrid.UltraCombo
        {
            public UserControl1()
            {
                InitializeComponent();
            }

            protected override void OnCreateControl()
            {            
                base.OnCreateControl();

                EditorButton editorButton1 = new Infragistics.Win.UltraWinEditors.EditorButton();
                editorButton1.Text = "a";
                this.ButtonsRight.Add(editorButton1);
            }
        }

Children