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