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

DropDownList Formatting

6 Answers 181 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 14 Nov 2018, 04:25 PM

Hi, I was wondering if it was possible for a DescriptionTextListDataItem to have children in a dropdownlist control?

See on video DropDownList

I have the attached so far

6 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 14 Nov 2018, 04:42 PM
This might be a better quality video https://youtu.be/nGZfsH4G-f8 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Nov 2018, 11:23 AM
Hello, Mark, 

The provided sample video is greatly appreciated. RadDropDownList doesn't offer nested items similar to RadMenu. However, you can create a custom RadListVisualItem which hosts a RadMenuItem that has nested menu items. Following the demonstrated approach in the following help article I have prepared the below code snippet: https://docs.telerik.com/devtools/winforms/dropdown-listcontrol-and-checkeddropdownlist/dropdownlist/custom-items

public RadForm1()
{
    InitializeComponent();
 
    this.radDropDownList1.CreatingVisualListItem += radDropDownList1_CreatingVisualListItem;
 
    for (int i = 0; i < 10; i++)
    {
        this.radDropDownList1.Items.Add("Item" + i);
    }
      
}
 
private void radDropDownList1_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
{
    args.VisualItem = new CustomVisualItem();
}
 
public class CustomVisualItem : RadListVisualItem
{
    protected override Type ThemeEffectiveType    
    {
        get   
        {
            return typeof(RadListVisualItem);    
        }
    }
 
    RadMenuItem item;
 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        
        item = new RadMenuItem("Test");
        for (int i = 0; i < 3; i++)
        {
            item.Items.Add(new RadMenuItem("Sub.Item" + i));
        }
          
        this.Children.Add(item);
    }
 
    public override void Synchronize()
    {
        base.Synchronize();
        this.DrawText = false;
        item.Text = this.Data.Text;
    }
}



In order to prevent the drop down from closing when you click the menu items you can cancel the RadDropDownList.PopupClosing event.

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best. 

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mark
Top achievements
Rank 1
answered on 20 Nov 2018, 04:27 PM

Many thanks Dess. However I did find another way of doing it. By repopulating the list when clicking on an item and stopping the list from closing. See below video for anyone that wants this kind of dropdownlist

https://youtu.be/VSSyvBxLWkI

This was done by identifying if to close the popup for keep it open from the dropdown - ListElement.MouseDown event. 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Nov 2018, 09:35 AM
Hello, Mark, 

It looks good. If you feel confident, I will encourage you to share your solution with the community so other customers can benefit from it.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mark
Top achievements
Rank 1
answered on 27 Nov 2018, 12:13 PM

Sure, this is everything. Hope it helps someone!

I am also using the Capture Plus Library

public bool ClosePopup = true;    
 
   private void combo_findaddress_GatherInfo(object sender, CancelEventArgs e)
        {
            if (combo_findaddress.SelectedItem == null)
            {
                if (combo_findaddress.Text.Length > 0)
                {
                    var BeginSearch = FindAddress.BasicAddress(combo_findaddress.Text);
                    combo_findaddress.Items.Clear();
                    List<MAB.PCAPredictCapturePlus.CapturePlusFindItem> objectList = BeginSearch.Items.OrderBy(o => o.Type).ToList();
 
                    foreach (var Address in objectList)
                    {
                        Telerik.WinControls.UI.DescriptionTextListDataItem Item = new Telerik.WinControls.UI.DescriptionTextListDataItem();
                        Item.Value = Address;
                        Item.Text = Address.Text;
                        Item.DescriptionText = Address.Description;
                        combo_findaddress.Items.Add(Item);
                    }
                }
            }
        }
 
        private void combo_findaddress_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
        {
            args.VisualItem.Padding = new System.Windows.Forms.Padding(2);
            args.VisualItem.DrawBorder = true;
        }
 
        private void combo_findaddress_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
        {
            args.VisualItem.Padding = new System.Windows.Forms.Padding(0, 3, 0, 3);
            args.VisualItem.NumberOfColors = 1;
            args.VisualItem.DrawBorder = true;
            args.VisualItem.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
            args.VisualItem.BorderBottomColor = Color.Black;
            args.VisualItem.BorderBottomWidth = 1;
            args.VisualItem.BorderTopWidth = 0;
            args.VisualItem.BorderLeftWidth = 0;
            args.VisualItem.BorderRightWidth = 0;
            args.VisualItem.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
        }  
 
private void combo_findaddress_SelectedValueChanged(object sender, EventArgs e)
        {
            if (combo_findaddress.SelectedValue != null)
            {
                CapturePlusFindItem Find = combo_findaddress.SelectedItem.Value as CapturePlusFindItem;
                RadDropDownList ListControl = sender as RadDropDownList;
                if (Find.Type == CapturePlusFindItemType.Postcode)
                {
                    ListControl.Items.Clear();
                    var AddrList = FindAddress.AdvancedAddress(Find.Text, Find.Id);
                    foreach (var Item in AddrList.Items)
                    {
                        Telerik.WinControls.UI.DescriptionTextListDataItem DataItem = new Telerik.WinControls.UI.DescriptionTextListDataItem();
                        DataItem.Value = Item;
                        DataItem.Text = Item.Text;
                        DataItem.DescriptionText = Item.Description;
                        ListControl.Items.Add(DataItem);
                    }
                }
                else if (Find.Type == CapturePlusFindItemType.Address)
                {
                    combo_findaddress.CloseDropDown();
                    var Address = FindAddress.RetrieveResult(Find.Id).Items.FirstOrDefault() ;
                    FormatAddress(Address);
                    combo_findaddress.Text = "";
                }
                ListControl.Refresh();
            }
        }
 
private void ListElement_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            RadListElement el = sender as RadListElement;
            RadListVisualItem visualItem = el.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
            CapturePlusFindItem FindItem = visualItem.Data.Value as CapturePlusFindItem;
 
            if (FindItem.Type == CapturePlusFindItemType.Address)
            {
                ClosePopup = true;
            }
            else if (FindItem.Type == CapturePlusFindItemType.Postcode)
            {
                ClosePopup = false;
            }
 
            Console.WriteLine("Clicked item: " + visualItem.Data.Text);
        }
        private void ArrowButton_Click(object sender, System.EventArgs e)
        {
            if (combo_findaddress.DropDownListElement.IsPopupOpen)
            {
                ClosePopup = true;
            }
            else
            {
                ClosePopup = false;
            }
        }
        private void combo_findaddress_PopupClosing(object sender, RadPopupClosingEventArgs args)
        {
            if (!ClosePopup)
            {
                args.Cancel = true;
            }
        }
 
        private void combo_findaddress_PopupClosed(object sender, RadPopupClosedEventArgs args)
        {
            combo_findaddress.Refresh();
        }
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Nov 2018, 08:57 AM
Hello, Mark,  

Thank you for sharing your code with the community.

I have also updated your Telerik points.


Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownList
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or