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
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
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:
- Drag a RadDropDownList on the form.
- Add items from by editing the Items in the designer or by clicking the Edit items link in the smart tag menu.
- Subscribe to the VisualListItemFormatting event.
- 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,
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.
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,