Button Added to DropDown won't show in a RadPageViewPage or in a RadWizardPage

4 posts, 0 answers
  1. Alessio Bulleri
    Alessio Bulleri avatar
    26 posts
    Member since:
    Sep 2008

    Posted 03 Oct Link to this post

    Hi all,

    some time ago starting from some code I found here, I wrote a method to add a button in a dropdownlist (I have used a label with an image instead of a button), it seems to work fine but if I use it with a dropdownlist that is contained in a RadWizard or RadTreeView page, the button is shown only if that page is the selected page when the form is loaded, but is not shown when I click on a Tab move to the page that contains the dropdownlist.

    I usually add call the method in the Load event of the form, but I've tried tu use other events with effects.

     

    This is the method :

     

            public static void ButtonizeDropDown(RadDropDownList ddlistControl, EventHandler OnClick, out RadLabelElement btnElement) {
                btnElement = null;
                EventHandler onLabelElementClicked = (object s, EventArgs ea) => { ddlistControl.SelectedIndex = -1; };
                if (OnClick != null) onLabelElementClicked = (object s, EventArgs ea) => { OnClick(ddlistControl,ea); };
                ddlistControl.BeginInit();
                RadLabelElement lbl = new RadLabelElement();
                btnElement = lbl;
                lbl.Click += onLabelElementClicked;
                lbl.Margin = new Padding(0, 0, 0, 0);
                lbl.AutoSize = false;
                lbl.Text = "";
                lbl.Tag = ddlistControl;
                lbl.Image = new Bitmap(global::K2O.UI.Properties.Resources.Delete_Thin_BW_UltraLight_12);
                lbl.ImageAlignment = ContentAlignment.MiddleCenter;
                lbl.TextAlignment = ContentAlignment.MiddleCenter;
                lbl.TextImageRelation = TextImageRelation.Overlay;
                lbl.Alignment = ContentAlignment.MiddleCenter;
                ddlistControl.DropDownListElement.EditableElement.ShouldPaint = false;
                RadDropDownTextBoxElement textBoxElement = ddlistControl.DropDownListElement.EditableElement.TextBox;
                RadTextBoxItem textboxitem = textBoxElement.TextBoxItem;
                ddlistControl.DropDownListElement.EditableElement.TextBox.Children.Remove(textboxitem);
               
                lbl.Size = new System.Drawing.Size(textBoxElement.Size.Height, textBoxElement.Size.Height);
                StackLayoutElement stackPanel = new StackLayoutElement();
                stackPanel.Orientation = Orientation.Horizontal;
                stackPanel.Margin = new Padding(0, 0, 0, 0);
                stackPanel.Size = lbl.Size;
                stackPanel.Children.Add(lbl);
                DockLayoutPanel dockPanel = new DockLayoutPanel();
                dockPanel.Size = lbl.Size;
                dockPanel.Children.Add(stackPanel);
                dockPanel.Children.Add(textboxitem);
                DockLayoutPanel.SetDock(textboxitem, Dock.Right);
                DockLayoutPanel.SetDock(stackPanel, Dock.Left);
                ddlistControl.DropDownListElement.EditableElement.TextBox.Children.Add(dockPanel);
                if (ddlistControl.DropDownStyle == RadDropDownStyle.DropDownList) {
                    textboxitem.ReadOnly = true;
                    ddlistControl.DropDownListElement.EditableElement.TextBox.Visibility = ElementVisibility.Visible;
                    ddlistControl.DropDownListElement.EditableElement.TextBox.Enabled = true;
                    lbl.Enabled = true;
                    lbl.Visibility = ElementVisibility.Visible;
                }
                //Per fare in modo che tutti gli elementi del controllo acquistino lo stesso stato (Enabled/Disabled) del controllo stesso;
                ddlistControl.Enabled = !ddlistControl.Enabled;
                ddlistControl.Invalidate();
                ddlistControl.Enabled = !ddlistControl.Enabled;
                ddlistControl.EndInit();
            }

     

    can you please tell me what I must change to have it work in every page of a RadPageView or RadWizard ?

     

    Thanks

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 04 Oct Link to this post

    Hello, Alessio,

    I have simplified the method and it works as expected on my side. Please note that there is no need to use StacklayoutElement which has only one element inside it. You should leave the AutoSize property of all elements to true as well:
    public static void ButtonizeDropDown(RadDropDownList ddlistControl, EventHandler OnClick)
    {
        RadLabelElement lbl = new RadLabelElement();
        lbl.Margin = new Padding(0, 0, 0, 0);
        lbl.Text = "";
        lbl.Tag = ddlistControl;
        lbl.Image = Image.FromFile(@"c:\img\delete.png");
        lbl.ImageAlignment = ContentAlignment.MiddleCenter;
        lbl.TextAlignment = ContentAlignment.MiddleCenter;
        lbl.TextImageRelation = TextImageRelation.Overlay;    
        lbl.Alignment = ContentAlignment.MiddleCenter;
     
        RadDropDownTextBoxElement textBoxElement = ddlistControl.DropDownListElement.EditableElement.TextBox;
        RadTextBoxItem textboxitem = textBoxElement.TextBoxItem;
        textBoxElement.Children.Remove(textboxitem);
     
        DockLayoutPanel dockPanel = new DockLayoutPanel();
        dockPanel.Children.Add(lbl);
        dockPanel.Children.Add(textboxitem);
        DockLayoutPanel.SetDock(textboxitem, Telerik.WinControls.Layouts.Dock.Right);
        DockLayoutPanel.SetDock(lbl, Telerik.WinControls.Layouts.Dock.Left);
        textBoxElement.Children.Add(dockPanel);
     
        if (ddlistControl.DropDownStyle == RadDropDownStyle.DropDownList)
        {
            textboxitem.ReadOnly = true;
            ddlistControl.DropDownListElement.EditableElement.TextBox.Visibility = ElementVisibility.Visible;
            ddlistControl.DropDownListElement.EditableElement.TextBox.Enabled = true;
            lbl.Enabled = true;
            lbl.Visibility = ElementVisibility.Visible;
        }     
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Alessio Bulleri
    Alessio Bulleri avatar
    26 posts
    Member since:
    Sep 2008

    Posted 04 Oct in reply to Dimitar Link to this post

    Hi Dimitar, thanks for your answer.
    You're right, the stack panel is unuseful.

    Anyway your code seems to have the same problem as mine if I put it in my Application, while both (mine and yours) works fine if used in a new solution.

    So I must investigate the problem a little deeper.

    In my Application I'm using Winforms Controls 2016.3.1024.40, may this have something to do with the problem ?

    Thanks Again.

  4. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 05 Oct Link to this post

    Hi, Alessio,

    I have attached my test project. Could you please check it and let me know what I need to change in order to reproduce this?

    I am looking forward to your reply.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top