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

Text Color

1 Answer 70 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.
Ching-Yen
Top achievements
Rank 1
Ching-Yen asked on 24 Apr 2008, 04:32 PM
May I know how can I change the combo box text color, example
the combobox having a list like below
Red
Blue
Green
White
Black

When that item is selected, the forecolor show on the combo box is the text color.

below are some of my code...
============================================

6:          For i As Integer = 0 To _Color.Items.Count - 1
7:              Dim item As New Telerik.WinControls.UI.RadComboBoxItem()
8:              Dim fillElement As Telerik.WinControls.Primitives.FillPrimitive = DirectCast(item.Children(0), Telerik.WinControls.Primitives.FillPrimitive)
9:              fillElement.BackColor = _Color.Item(i).CoverColor
10:             fillElement.BackColor2 = _Color.Item(i).CoverColor
11:             fillElement.BackColor3 = _Color.Item(i).CoverColor
12:             fillElement.BackColor4 = _Color.Item(i).CoverColor
                item.ForeColor = _Color.Item(i).FontColor
13:             item.Text = _Color.Item(i).Name
14:             item.Value = _Color.Item(i).Index
15:             _cboCTRL.Items.Add(item)
16:         Next

====================================
    Private Sub _ComboColor_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles _cboCoverColor.SelectedValueChanged

1:      Dim item As RadComboBoxItem = DirectCast(_cboCoverColor.SelectedItem, RadComboBoxItem)
2:      If item Is Nothing Then
3:          Return
4:      End If

        _cboCoverColor.ForeColor = item.ForeColor
    End Sub
================================================

but seems like no luck... i only manage to change the drop down text to the color I would like it to be, but, not the text color while it's selected.

Please advice.

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 25 Apr 2008, 11:47 AM
Hi Ching-Yen,

Thank you for the question.

RadComboBox supports flexible visual style settings and you could achieve your scenario. You should set the color properties on every single item, and then by using the SelectedIndexChanged event apply the same color to the selected text. Please review the code-block below as an example:
 
Public Partial Class Form1  
    Inherits Form  
    Public Sub New()  
        InitializeComponent()  
    End Sub 
 
    Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs)  
        Dim itemRed As New RadComboBoxItem()  
        itemRed.ForeColor = Color.Red  
        itemRed.Text = "Red" 
 
        Dim itemBlue As New RadComboBoxItem()  
        itemBlue.ForeColor = Color.Blue  
        itemBlue.Text = "Blue" 
 
        Dim itemGreen As New RadComboBoxItem()  
        itemGreen.ForeColor = Color.Green  
        itemGreen.Text = "Green" 
 
        Dim itemWhite As New RadComboBoxItem()  
        itemWhite.ForeColor = Color.White  
        (DirectCast(itemWhite.Children(0), FillPrimitive)).BackColor = Color.Black  
        (DirectCast(itemWhite.Children(0), FillPrimitive)).GradientStyle = Telerik.WinControls.GradientStyles.Solid  
        itemWhite.Text = "White" 
 
        Dim itemBlack As New RadComboBoxItem()  
        itemBlack.ForeColor = Color.Black  
        itemBlack.Text = "Black" 
 
 
        Me.radComboBox1.Items.AddRange(itemRed, itemBlue, itemGreen, itemWhite, itemBlack)  
        Me.radComboBox1.NullText = "select the color..." 
        Me.radComboBox1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList  
    End Sub 
 
    Private Sub radComboBox1_DropDownClosed(ByVal sender As ObjectByVal args As RadPopupClosedEventArgs)  
        Me.radComboBox1.SelectionLength = 0  
    End Sub 
 
    Private Sub radComboBox1_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs)  
        (DirectCast(Me.radComboBox1.RootElement.Children(0).Children(2).Children(0).Children(0), RadTextBoxItem)).ForeColor = (DirectCast(Me.radComboBox1.SelectedItem, RadComboBoxItem)).ForeColor  
        (DirectCast(Me.radComboBox1.RootElement.Children(0).Children(2).Children(0).Children(0), RadTextBoxItem)).BackColor = (DirectCast((DirectCast(Me.radComboBox1.SelectedItem, RadComboBoxItem)).Children(0), FillPrimitive)).BackColor  
    End Sub 
 
 
End Class 

I hope this helps. If you need additional assistance, do not hesitate to contact me again.

 
Regards,
Martin Vasilev
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
Ching-Yen
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or