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
1834
Problems With Custom UltraComboEditor's DropDownEditorButton
posted

Hi,

I have a screen that will need multiple combo boxes, and they will all need the same special stuff, so I am trying to make my own control that inherits from UltraComboEditor that I can reuse.

In addition to the standard drop-down functionality, I will need an extra drop-down button that drops down an UltraGrid for quick-summary purposes.  (Actually, I will need three buttons, but I imagine the process is the same for the second two, so I'm starting with one.)

My strategy is to have member variables for the button (DropDownButtonEditor '_button') and the grid (UltraGrid '_grid').  In the constructor of this TestComboEditor class, I add the button to the class's ButtonsRight collection, set some Appearance properties (add an image), and set the Control property of _button to be the grid.  I want to use the BeforeDropDown event to retrieve and set the DataSource for the grid.

The first problem I have is that there are two editor buttons being shown in addition to the standard drop-down button.  I thought maybe a button was being added to the collection twice, so in the constructor of TestComboEditor , I surrounded the code that adds the _button to the ButtonsRight collection with 'if (!this.DesignMode).  But that led to a 'Key already exists' exception in the constructor when the _button was being added to the ButtonsRight collection--apparently, just placing the TestComboEditor  control on the form in the screen designer added a new DropDownEditorButton and added it to the ButtonsRight collection.  So I changed the conditional around to only add the button if in DesignMode, and then I get nothing.

Now the problem is that I can't get it to work without throwing the 'Key already exists' exception.  I really don't know what is going on.  Any advice?  I've attached the code I'm using for the TestComboEditor class.

Thanks,

J

Update:  You can get the 'Key already exists' error in VS directly--add the control to a screen and save, close the screen, and then open back up in the designer.

Parents
  • 469350
    Offline posted

    This will be very tricky to do at design-time. If you add a button to the ButtonsRight collection in the constructor of the derived class, then this button will get added to the control when you place your control on a form. It will then get serialized when you save the form. The next time you open the form designer, the control will get deserialized, which will recreate the button, which is already there because you added it in the constructor.

    I'm a little bit rusty on this, but I think the thing to do is to add the button in OnCreateControl instead of in the constructor.

Reply Children