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
725
UserControl as UltraTextEditor draws extra button on Win Form
posted

Before I describe the problem, let me give some background on what I'm trying to accomplish because this may not be the best method after all.

THE BACKGROUND:

I have a list of Code / Numeric Value pairs that I want to be able to display in a dual column drop down fashion. The user should be able to type either the single digit code or the actual numeric value in the control and upon exiting the control will always return the corresponding numeric value. The ability to type just the code speeds data entry for users more familiar with the system and the drop down list and ability to type the actual numeric value are for those less familiar.

Next - I need this functionality in a UltraGrid Column that represents the numeric data as well as a stand alone control on a windows form.

To that end I found that using an UltraTextEditor with a RightButton as a DropDown that displayed an UltraGrid bound to the data worked flawlessly on the grid, however some of my filtering & validating was tied to the Parent Grid events.

I was able to then create my own user control that inherits an UltraTextEditor, create an UltraGrid & the DropDown Button in code and bind the grid to the button. Now all the filtering and validation happen on the events inside my user control.

So far - So good.

Next I was able to use an UltraControlContainerEditor to place my user control on the grid column and "wire it up" and this too works perfectly.

THE PROBLEM:

When I try and place my user control on a WinForm - at design time (depending on the various things I have tried thus far) it displays either a single DropDownButton on the Right or none at all; however at Run Time there are TWO DropDownButtons on the right. The innermost one drops/displays the list as expected and the rest of the control works as planned also - there is just a phantom/dummy/extra button on the right of the control I can't get to go away.

Obviously I'm a little over my head here and any input is greatly appreciated.

I am coding with Visual Studio 2012 in VB.net using Infragistics 12.1.20121.2135 CLR4

Here is a sample App that shows problem

https://p2p.aep.com:443/AEPLargeFile/fileDownload.dsp?isEncrypted=true&isEnSet=true&fileStage=30&fileName=L1uhyxfMPhCJil7UKjzBiHZllwIFc1jWUhHJzb2a3dxkbYxO9SBibA%3D%3D&fop=a82b55b0253a11e38bfed34efa60426f8&version=v2

Thanks

Steve

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Steve,

    I took a quick look at your sample project. You are deriving from UltraTextEditor and your UltraTextEditor control has a DropDownEditorButton in the ButtonsRight collection. This presumably got created the first time you dropped the control on the form. But ButtonsRight is a public collection and gets serialized in the designer.

    Forget about your derived control for a moment and imagine that you simply placed a regular UltraTextEditor on a form and added a DropDownEditorButton to the ButtonsRight collection. If you closed the form and re-opened it, that button would still be there - you would not have to add it again every time you opened the form designer.

    So, since the button is public, the button that exists in your derived control is getting serialized by the designer. You can see it in the form's InitializeComponent code. Then when you run the application a new instance of your control is created - the constructor gets called and your code in the constructor adds a button to the collection. Then the InitializeComponent code gets called and put the origin button back in, so you end up with two buttons.

    What you need is to only add the button when the control is created the first time, not every time a new instance is constructed. So I think if you override the OnCreateControl method and move your code for adding the DropDownEditorButton into that method, it will work.


        Protected Overrides Sub OnCreateControl()
            MyBase.OnCreateControl()

            If Not Me.DesignMode Then
                ' Build Drop Down Button & Attach Grid
                Me.ResetButtonsRight()
                Dim ddb As New DropDownEditorButton
                ddb.Control = ug
                Me.ButtonsRight.Add(ddb)
            End If
        End Sub

Reply Children
No Data