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

Item background color

3 Answers 332 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
zagy
Top achievements
Rank 1
zagy asked on 16 Dec 2007, 07:56 AM
Hi,

I'm trying to use your ComboBoxElement control inside a RibbonBar.

My goal is to create a combo box "color picker" where the user would click on the drop down menu and each of the items would have it's own color. Here's what I have tried:

private

void InitBackgroundCombo()
{
    // this returns all the color in the Color struct
    
Color[] systemColors = GetAllColors();
    
for (int i = 0; i < systemColors.Length; i++)
    {
        
RadComboBoxItem item = new RadComboBoxItem();
        item.ForeColor = systemColors[i];
        item.Text = systemColors[i].Name;
        item.BackColor = systemColors[i];
        cbxBackground.Items.Add(item);
    }
 }



This doesn't work though. The ForeColor property works but not the BackColor. The BackColor is always White.

Can you help?

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 18 Dec 2007, 06:37 PM
Hello zagy,

The BackColor property actually comes from the base class (VisualElement) and it is not intended to set by it the color of the RadComboBoxItem background.In your case I would suggest to you to access the FillPrimitive element in the item's Children collection like this: 

    FillPrimitive fillElement = item.Children[0] as FillPrimitive;

Then you can access all FillPrimitive properties that control the visual presentation of the item's background: BackColor, BackColor2, GradientStyle, NumberOfColors, etc.

If you have any additional questions, please do not hesitate to write us.

 
Kind regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
zagy
Top achievements
Rank 1
answered on 20 Dec 2007, 12:18 PM
Hi,

Your solution does work. But now I have additional questions:

When you hover the mouse over an item in the combobox:
- first you get that nice orange bar (indicating that you are over that bar)
- but when you move the mouse away from the item the hover bar disappears but so does half of the item's color. How to get that back?

The other problem is: When I select the item, I want the combobox to be colored with the same color as the selected item but this doesn't work.

I tried setting:
- cbxColors.BackColor ...

When this didn't work I tried your FillPrimitives approach (I tried accessing the primitive from both cbxColor and cbxColor.TextBoxElement)

Can you help?
0
Georgi
Telerik team
answered on 21 Dec 2007, 02:35 PM
Hi zagy,

The reason for this behavior of RadComboBoxItem is the theme settings that are applied at runtime. You could change the currently used theme with your custom one where you have changed the settings for the item's FillPrimitive.

As to the BackColor of the text part of the RadComboBox, you should set it to RadTextBoxItem element of the control structure. If you use the latest version of RadControls, it can be accessed like this:

    radComboBox1.ComboBoxElement.TextBoxElement.TextBoxItem.BackColor = Color.Aqua;

or if you use a previous version - using the following row:

    (radComboBox1.RootElement.Children[0] as RadComboBoxElement).TextBoxElement.TextBoxItem.BackColor = Color.Aqua;

I hope this helps. Let us know if we could be of any further assistance.

Greetings,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
zagy
Top achievements
Rank 1
Answers by
Georgi
Telerik team
zagy
Top achievements
Rank 1
Share this question
or