Item background color

4 posts, 0 answers
  1. zagy
    zagy avatar
    7 posts
    Member since:
    Aug 2007

    Posted 16 Dec 2007 Link to this post

    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?
  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 18 Dec 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. zagy
    zagy avatar
    7 posts
    Member since:
    Aug 2007

    Posted 20 Dec 2007 Link to this post

    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?
  5. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 21 Dec 2007 Link to this post

    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
Back to Top