Changing Expander Icon Color When the RadTreeView is Disabled UI for WinForms
Environment
| Product Version | Product | Author |
|---|---|---|
| 2025.3.812 | RadTreeView for WinForms | Dinko Krastev |
Description
In this tutorial, we will demonstrate how to change the color of the expander icon in both expanded and collapsed states when the RadTreeView control is disabled. An important step in our approach is that we will need to force the RadTreeView control to update. The code below demonstrates how to do that.
The approach is designed while the VisualStudio2022Light theme is applied to the control.
Solution
To change the disabled icon color for the expanded state and refresh it when the RadTreeView is enabled or disabled, follow these steps:
- Handle the
NodeFormattingevent of the RadTreeView. - Check the
Enabledproperty of the control and theExpandedproperty of the expander element. - Use the
Updatemethod with theResetparameter to refresh the formatting after changing the Enabled state.
Here is the updated code:
private void RadTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
if (this.radTreeView1.TreeViewElement.Enabled)
{
e.NodeElement.ExpanderElement.ForeColor = Color.Gray; // Enabled state color.
}
else
{
if (e.NodeElement.ExpanderElement.Expanded)
{
e.NodeElement.ExpanderElement.ForeColor = Color.Green; // Disabled and expanded state color.
}
else
{
e.NodeElement.ExpanderElement.ForeColor = Color.Red; // Disabled and collapsed state color.
}
}
}
private void radButton1_Click(object sender, EventArgs e)
{
this.radTreeView1.TreeViewElement.Enabled = !this.radTreeView1.TreeViewElement.Enabled; // Toggle Enabled state.
this.radTreeView1.TreeViewElement.Update(Telerik.WinControls.UI.RadTreeViewElement.UpdateActions.Reset); // Refresh the control.
}
Explanation
-
NodeFormatting: Customizes the visual elements of the tree nodes, including the expander icon. -
UpdateActions.Reset: Forces the control to refresh and reapply the formatting logic.