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

Change DropDownList item color

9 Answers 142 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
miki
Top achievements
Rank 1
miki asked on 21 Dec 2014, 11:55 AM
I have my object and all it's properties that i want to populate inside my DropDownList and i am doing this in this way:

            DescriptionTextListDataItem item = new DescriptionTextListDataItem();
            item.Text = "This is string test";
            radDropDownListAdapter.Items.Add(item);
            string str1 =
                "Name:: " + "test 1" + Environment.NewLine +
                "Age:: " + "test 2" + Environment.NewLine +
                "ID: : " + "test 3" + Environment.NewLine +
                "Scor: " + "test 4" + Environment.NewLine;

            item.DescriptionText = str1;
            radDropDownListAdapter.SelectedIndex = 0;

Currently i am using VisualStudio2012Light theme and you can see the result in my attach file.
As you can see all my object propertiesrarely seen because it's black and background is blue so my question is how to change this color from black ?

9 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Dec 2014, 12:08 PM
Hi Miki,

Thank you for writing.

I managed to reproduce the described case and I can confirm it is an issue. I have logged it in our feedback portal. You can add your vote and subscribe for status updates here: http://feedback.telerik.com/Project/154/Feedback/Details/147335-fix-raddropdownlist-the-description-text-is-not-clearly-visible-for-the-select.

Your Telerik Points have been updated for this report. 

To change the color, you can use the VisualItemFormatting event as show below:
void radDropDownList1_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    if (args.VisualItem.Selected && radDropDownList1.ThemeName == "VisualStudio2012Dark")
    {
        args.VisualItem.BackColor = Color.DarkBlue;
    }
    else
    {
        args.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
miki
Top achievements
Rank 1
answered on 24 Dec 2014, 03:28 PM
Hi and thank you for your help.
Currently there is no change and the color is still the same.
0
Stefan
Telerik team
answered on 24 Dec 2014, 03:36 PM
I have tested this code with our latest version and it was working correctly. Still, you can try the following snippet too:
void radDropDownList1_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    if (args.VisualItem.Selected && radDropDownList1.ThemeName == "VisualStudio2012Dark")
    {
        args.VisualItem.DrawFill = true;
        args.VisualItem.BackColor = Color.DarkBlue;
        args.VisualItem.GradientStyle = GradientStyles.Solid;
    }
    else
    {
        args.VisualItem.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
    }
}

Just to make sure we are allowed to set the BackColor, we will set the DrawFill too.

If this does not help, please get back to me with a sample app, where the undesired behavior can be reproduced and I will gladly look into it.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
miki
Top achievements
Rank 1
answered on 25 Dec 2014, 02:16 PM
I'm sorry if I was not clear, but what I meant is change the text color
0
Stefan
Telerik team
answered on 25 Dec 2014, 03:12 PM
Hello,

To do that, again in the formatting event, you should look for the DescriptionTextListVisualItem, and change the desired colors. You can even put different colors for the main text and the description text:
void radDropDownList1_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    DescriptionTextListVisualItem descriptionItem = args.VisualItem as DescriptionTextListVisualItem;
    if (descriptionItem != null)
    {
        descriptionItem.ForeColor = Color.Blue;
        descriptionItem.DescriptionContent.ForeColor = Color.Red;
    }
}

I hope that you find this information useful.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
miki
Top achievements
Rank 1
answered on 25 Dec 2014, 08:47 PM
Thanks a lot !
This is exactly what i am looking for.
0
VaL
Top achievements
Rank 1
answered on 12 Apr 2018, 07:34 AM

Hello!

Sorry to revive this old thread, but what I'm trying to do starts exactly from here...

How can I set a different color in DescriptionTextListVisualItem based on the value contained in the item?

I can't find how to reach the DescriptionTextListDataItem from the corresponding DescriptionTextListVisualItem.

Thanks!

0
Hristo
Telerik team
answered on 12 Apr 2018, 04:07 PM
Hello Valerio,

Thank you for writing.

You can access the data item through the DataItem property of the visual item. Assuming you are having the colors stored in its Tag property, you can handle the VisualListItemFormatting event this way: 
private void RadDropDownList1_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    DescriptionTextListDataItem data = args.VisualItem.Data as DescriptionTextListDataItem;
    if (data != null)
    {
        args.VisualItem.BackColor = (Color)data.Tag;
    }
}

I hope this helps. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
VaL
Top achievements
Rank 1
answered on 13 Apr 2018, 06:56 AM

That'is it!

Thank you Hristo!

Tags
DropDownList
Asked by
miki
Top achievements
Rank 1
Answers by
Stefan
Telerik team
miki
Top achievements
Rank 1
VaL
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or