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
935
Custom control derived from UltraComboEditor with Buttons Left
posted

Hello,

I am trying to create a custom control derived from a UltraComboEditor which is preconfigured with a stateEditorbutton added to ButtonsLeft and the items list pre-populated. The StateEditor button would then have available methods to null/select items in the combo.

When I add the StateEditorButton "myCheckBox" to the button collection it will show up on the design surface. However, the designer also generates code to add the same stateEditor button which when run then fails with the exception for invalid key (as the button is already in the collection.)

Also, the items being configured are added at Design time even though the code is for !DesignMode.

I would appreciate any suggestions on how to pre-configure the buttons left. Also any samples for derived UltraComboEditor would be helpful.

Wendy

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Wendy,

    In what method of the derived control are you adding the button? My guess is that you are probably using the constructor. This won't work very well, because Visual Studio will serialize and deserialize the button. So when you open your form, you will add the button in your constructor and then VS tries to add it again when it deserializes the control.

    So what you really need here is a method that gets called after the control has been deserialized so you can add the button only if it does not already exist. 

    Luckily, there is already a method on the control which fires when deserialization is complete. So I recommend that you override the OnEndInit method. Call the base first. Then check to see if the button already exists in the ButtonsRight collection and if not, add it.

Children