This is a migrated thread and some comments may be shown as answers.

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

3 Answers 82 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Alessio Bulleri
Top achievements
Rank 1
Alessio Bulleri asked on 03 Oct 2017, 03:52 PM

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

 

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Oct 2017, 08:37 AM
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.
0
Alessio Bulleri
Top achievements
Rank 1
answered on 04 Oct 2017, 02:48 PM

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.

0
Dimitar
Telerik team
answered on 05 Oct 2017, 08:44 AM
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.
Tags
DropDownList
Asked by
Alessio Bulleri
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Alessio Bulleri
Top achievements
Rank 1
Share this question
or