Skip to content

Commit 3641b27

Browse files
authored
Merge pull request #804 from telerik/new-kb-treeview-change-disabled-icon-color-c73120d94b0a433b8273b14393ca8513
Added new kb article treeview-change-disabled-icon-color
2 parents 03a09d8 + 1382195 commit 3641b27

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Changing Expander Icon Color When the RadTreeView is Disabled UI for WinForms
3+
description: Learn how to change the expander icon color in the disabled RadTreeView for UI for WinForms.
4+
type: how-to
5+
page_title: Adjusting Expander Icon Color in Disabled RadTreeView for WinForms
6+
meta_title: Adjusting Expander Icon Color in Disabled RadTreeView for WinForms
7+
slug: treeview-change-disabled-icon-color
8+
tags: treeview, ui for winforms, disabled icon, expanded state, node formatting
9+
res_type: kb
10+
ticketid: 1700586
11+
---
12+
13+
## Environment
14+
15+
|Product Version|Product|Author|
16+
|----|----|----|
17+
|2025.3.812|RadTreeView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)|
18+
19+
## Description
20+
21+
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.
22+
23+
>note The approach is designed while the VisualStudio2022Light theme is applied to the control.
24+
25+
## Solution
26+
27+
To change the disabled icon color for the expanded state and refresh it when the RadTreeView is enabled or disabled, follow these steps:
28+
29+
1. Handle the `NodeFormatting` event of the RadTreeView.
30+
2. Check the `Enabled` property of the control and the `Expanded` property of the expander element.
31+
3. Use the `Update` method with the `Reset` parameter to refresh the formatting after changing the Enabled state.
32+
33+
Here is the updated code:
34+
35+
````C#
36+
37+
private void RadTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
38+
{
39+
if (this.radTreeView1.TreeViewElement.Enabled)
40+
{
41+
e.NodeElement.ExpanderElement.ForeColor = Color.Gray; // Enabled state color.
42+
}
43+
else
44+
{
45+
if (e.NodeElement.ExpanderElement.Expanded)
46+
{
47+
e.NodeElement.ExpanderElement.ForeColor = Color.Green; // Disabled and expanded state color.
48+
}
49+
else
50+
{
51+
e.NodeElement.ExpanderElement.ForeColor = Color.Red; // Disabled and collapsed state color.
52+
}
53+
}
54+
}
55+
56+
private void radButton1_Click(object sender, EventArgs e)
57+
{
58+
this.radTreeView1.TreeViewElement.Enabled = !this.radTreeView1.TreeViewElement.Enabled; // Toggle Enabled state.
59+
this.radTreeView1.TreeViewElement.Update(Telerik.WinControls.UI.RadTreeViewElement.UpdateActions.Reset); // Refresh the control.
60+
}
61+
62+
````
63+
64+
### Explanation
65+
- `NodeFormatting`: Customizes the visual elements of the tree nodes, including the expander icon.
66+
- `UpdateActions.Reset`: Forces the control to refresh and reapply the formatting logic.
67+
68+
## See Also
69+
70+
* [RadTreeView Overview](https://docs.telerik.com/devtools/winforms/controls/treeview/treeview)
71+
* [Node Formatting in RadTreeView](https://docs.telerik.com/devtools/winforms/controls/treeview/working-with-nodes/formatting-nodes)

0 commit comments

Comments
 (0)