New to Telerik UI for WinFormsStart a free 30-day trial

Formatting Items

Updated over 6 months ago

Items appearance in RadListControl can be customized by making use of the VisualItemFormatting event. The following example, demonstrates how you can change the color of an item which is being selected.

By using this event to customize the items appearance, you should always provide an else clause, where you reset the appearance settings which you have introduced. This is necessary since RadListControl uses data virtualization, which might lead to undesired appearance results when items are being reused.

Figure 1: Formatting items

WinForms RadListControl Formatting Items

Formatting items

C#
Font font = new Font("Consolas", 14, FontStyle.Bold);
private void radListControl1_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    if (args.VisualItem.Selected)
    {
        args.VisualItem.NumberOfColors = 1;
        args.VisualItem.BackColor = Color.LightGreen;
        args.VisualItem.ForeColor = Color.Red;
        args.VisualItem.BorderColor = Color.Blue;
        args.VisualItem.Font = font;
    }
    else
    {
        args.VisualItem.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.BorderColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        args.VisualItem.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

Alternating Item Color

RadListControl supports alternating item color which can be easily enabled by just setting a couple of properties:

C#
radListControl1.EnableAlternatingItemColor = true;
radListControl1.ListElement.AlternatingItemColor = Color.Red;

Figure 2: AlternatingItemColor

WinForms RadListControl AlternatingItemColor

In this article
Alternating Item Color
Not finding the help you need?
Contact Support