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

Different colour ticks for checkboxes in CheckedListBox

2 Answers 28 Views
CheckedListBox
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 01 Oct 2018, 05:03 PM

Hi,

 

I'm creating a RadCheckedListBox at run time and adding various items to it, some of which are checked and others which are not. Based on other data, I would like to override the default colour of the "tick" (currently green) to red, but not for all items only some of them. Is this possible ?

Regards
Toby

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 02 Oct 2018, 10:21 AM
Hello Toby,

This can be achieved by styling the checkmark in the VisualItemFormatting event. Here is the code:
private void RadCheckedListBox1_VisualItemFormatting(object sender, Telerik.WinControls.UI.ListViewVisualItemEventArgs e)
{
    var item = e.VisualItem as SimpleListViewVisualItem;
    if (item != null && item.Data.CheckState == Telerik.WinControls.Enumerations.ToggleState.On)
    {
        var checkBox = item.ToggleElement as ListViewItemCheckbox;
 
        if (item.Data.Text == "Item5")
        {
            checkBox.CheckMarkPrimitive.CheckElement.ForeColor = Color.Red;
        }
        else
        {
            checkBox.CheckMarkPrimitive.CheckElement.ResetValue(CheckPrimitive.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Toby
Top achievements
Rank 1
answered on 03 Oct 2018, 09:21 AM
That's perfect thanks, your detailed knowledge of the Telerik classes is amazing!
Tags
CheckedListBox
Asked by
Toby
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Toby
Top achievements
Rank 1
Share this question
or