radDropDownList even spacing on multiple items

3 posts, 1 answers
  1. Martin
    Martin avatar
    35 posts
    Member since:
    Jun 2014

    Posted 25 Feb 2015 Link to this post

    Hi Folks.
    So I have a radDropDownList which is populated from a table through Entity Framework and LINQ.

    I used to do this (with a regular combo-box) via a stored procedure and adding column to the dataset. I could then show something like ItemCode and ItemDescription in a combo-box with the ID stored in the value member. I would then set the combo Font to CourierNew which evenly spaced the ItemCode and ItemDescription when the list was 'dropped down'. All nice and neat.

    Anyway - doing something similar with the radDropDownList does not work. The population is fine (you can see the ItemCode and ItemDescription) but they are not evenly spaced when the list is 'dropped down'.

    I've set the font to couriernew and also the font in the DropdownListElement.Font AND in the DropdownListElement.ListElement.Font

    Anyone got any ideas on formatting?
    Thanks.
  2. Answer
    Peter
    Admin
    Peter avatar
    1148 posts

    Posted 02 Mar 2015 Link to this post

    Hi Martin,

    Thank you for the writing.

    I am not sure that I completely understand your scenario, following the description. That is why I would ask you to provide a more detailed explanation - a sample project with the regular combo-box would really help.

    In case that you want to format the list items with same font as the control you can set the font directly to the control and using the VisualListItemFormatting event you can set same font to the list items:
    public Form1()
    {
        InitializeComponent();
        this.radDropDownList1.Font = new System.Drawing.Font("Courier New", 15F, System.Drawing.FontStyle.Regular);
        this.radDropDownList1.VisualListItemFormatting += radDropDownList1_VisualListItemFormatting;
        this.radDropDownList1.AutoSizeItems = true;
    }
     
    void radDropDownList1_VisualListItemFormatting(object sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
    {
        args.VisualItem.Font = this.radDropDownList1.Font;
    }

    In case that you want to use a ListItem which have a description text below you should set DescriptionTextMember in addition to DisplayMember:
    DataTable dt = new DataTable();
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Description", typeof(string));
    dt.Rows.Add("Name", "Description");
    dt.Rows.Add("Name2", "Description");
    dt.Rows.Add("Name3", "Description");
    this.radDropDownList1.DisplayMember = "Name";
    this.radDropDownList1.DescriptionTextMember = "Description";
    this.radDropDownList1.DataSource = dt;

    I hope this is a suitable for your scenario.

    Regards,
    Peter
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin
    Martin avatar
    35 posts
    Member since:
    Jun 2014

    Posted 05 Mar 2015 in reply to Peter Link to this post

    Thanks!
    That is exactly what I was looking for and it works a treat!
    The formatting is perfect.
Back to Top