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

radDropDownList even spacing on multiple items

2 Answers 147 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 25 Feb 2015, 04:06 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 02 Mar 2015, 10:48 AM
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.

 
0
Martin
Top achievements
Rank 1
answered on 05 Mar 2015, 03:08 PM
Thanks!
That is exactly what I was looking for and it works a treat!
The formatting is perfect.
Tags
DropDownList
Asked by
Martin
Top achievements
Rank 1
Answers by
Peter
Telerik team
Martin
Top achievements
Rank 1
Share this question
or