DropDownList Formatting

7 posts, 0 answers
  1. Mark
    Mark avatar
    4 posts
    Member since:
    Nov 2018

    Posted 14 Nov Link to this post

    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

  2. Mark
    Mark avatar
    4 posts
    Member since:
    Nov 2018

    Posted 14 Nov in reply to Mark Link to this post

    This might be a better quality video https://youtu.be/nGZfsH4G-f8 
  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    2938 posts

    Posted 15 Nov Link to this post

    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.
  4. Mark
    Mark avatar
    4 posts
    Member since:
    Nov 2018

    Posted 20 Nov Link to this post

    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. 

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    2938 posts

    Posted 22 Nov Link to this post

    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.
  6. Mark
    Mark avatar
    4 posts
    Member since:
    Nov 2018

    Posted 27 Nov Link to this post

    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();
            }
  7. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    2938 posts

    Posted 28 Nov Link to this post

    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.
Back to Top