RadDropdownlist should look like combobox

5 posts, 0 answers
  1. BB
    BB avatar
    13 posts
    Member since:
    Mar 2007

    Posted 30 Dec 2010 Link to this post

    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.

     

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 30 Dec 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 03 Jan 2011 Link to this post

    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.
  5. BB
    BB avatar
    13 posts
    Member since:
    Mar 2007

    Posted 04 Jan 2011 Link to this post

    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.

  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 05 Jan 2011 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready