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

RadDropdownlist should look like combobox

4 Answers 183 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
BB
Top achievements
Rank 1
BB asked on 30 Dec 2010, 09:39 AM

I need a control that is like the normal windows combobox, except
that for each item in the list the color for the background an forecolor differs, e.g.
Each Item has the same size (width, height)

ITEM 0      backcolour=red, forecolor=white
---------   
ITEM 1      backcolor=black forecolor=white
---------
ITEM 2      backcolor=blue,  forecolour=white
---------

ITEM 3      backcolor=green, forecolour=black

Thank you very much for the help.

 

4 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 30 Dec 2010, 10:18 AM
Hello BB,

As far as I'm aware, you can only change the BackColor via the Visual Style Builder and you would have to build tyour own theme for this control to so so. To change the ForeColor, you can use the following
For i As Integer = 0 To Me.RadDropDownList1.Items.Count
    If i Mod 2 = 0 Then
        Me.RadDropDownList1.Items(i).ForeColor = Color.Blue
    Else
        Me.RadDropDownList1.Items(i).ForeColor = Color.Red
    End If
Next i

You can find out more information on VSB at this link
Hope that helps
Richard
0
Ivan Todorov
Telerik team
answered on 03 Jan 2011, 05:06 PM
Hi Bernihard,

Thank you for writing.

The control that will solve the issue is the RadDropDownList. You can achieve the desired behavior by completing the following steps:

  1. Drag a RadDropDownList on the form.
  2. Add items from by editing the Items in the designer or by clicking the Edit items link in the smart tag menu.
  3. Subscribe to the VisualListItemFormatting event.
  4. Add the following code and then run the application:

Color[] backColors = { Color.Red, Color.Black, Color.Blue, Color.Green };
Color[] foreColors = { Color.White, Color.White, Color.White, Color.Black };
 
private void radDropDownList1_VisualListItemFormatting(object sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
{
    int index = args.VisualItem.Data.RowIndex;
    args.VisualItem.GradientStyle = GradientStyles.Solid;
    args.VisualItem.BackColor = backColors[index % backColors.Length];
    args.VisualItem.ForeColor = foreColors[index % foreColors.Length];
}

Hope this was helpful. If you have any further questions or you need further assistance, do not hesitate to write back.

Best wishes,
Ivan Todorov
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
BB
Top achievements
Rank 1
answered on 04 Jan 2011, 09:18 AM

Thank you very much for the help,

the control looks now good, except the header.

If I choose an item e.g.  list item 3   (backcolor green, forecolor white) ,  the   header should have the same look (color, size, width, font) green  like the item 3, and if i choose the item 2, the header should look like it  (backcolor blue, forecolor white) and so on.

If i load the form  (initialization of the control) the header should have the look of item 1 (backcolor black, forecolor white).

Thank you very much.

0
Ivan Todorov
Telerik team
answered on 05 Jan 2011, 03:37 PM
Hello Bernhard,

To achieve this, you should subscribe to the SelectedIndexChanged event and change the header's colors whenever the selected item is changed. For further details, please find the project attached.

I hope this helps. Should you have any further questions, do not hesitate to contact us.

Kind regards,
Ivan Todorov
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
DropDownList
Asked by
BB
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Ivan Todorov
Telerik team
BB
Top achievements
Rank 1
Share this question
or