@@ -52,12 +52,12 @@ To disable checkboxes for specific TreeView items based on a condition, use the
52
52
</TelerikTreeView>
53
53
54
54
<style>
55
- .disabled-checkbox .k-checkbox {
56
- opacity: 0.7 ;
55
+ .@(DisabledCheckboxClass) .k-checkbox {
56
+ opacity: 0.5 ;
57
57
pointer-events: none;
58
58
}
59
59
60
- .disabled-checkbox .k-treeview-leaf {
60
+ .@(DisabledCheckboxClass) .k-treeview-leaf {
61
61
opacity: 0.7;
62
62
pointer-events: none;
63
63
}
@@ -67,13 +67,14 @@ To disable checkboxes for specific TreeView items based on a condition, use the
67
67
private IEnumerable<TreeViewItem> FlatData { get; set; }
68
68
private IEnumerable<object> CheckedItems { get; set; } = new List<object>();
69
69
private IEnumerable<object> ExpandedItems { get; set; } = new List<TreeViewItem>();
70
+ private string DisabledCheckboxClass { get; set; } = "disabled-checkbox";
70
71
71
72
private void HandleOnItemRender(TreeViewItemRenderEventArgs args)
72
73
{
73
74
var item = args.Item as TreeViewItem;
74
75
if (!item.IsActive)
75
76
{
76
- args.Class = "disabled-checkbox" ;
77
+ args.Class = DisabledCheckboxClass ;
77
78
}
78
79
}
79
80
protected override void OnInitialized()
@@ -87,46 +88,46 @@ To disable checkboxes for specific TreeView items based on a condition, use the
87
88
List<TreeViewItem> items = new List<TreeViewItem>();
88
89
89
90
items.Add(new TreeViewItem()
90
- {
91
- Id = 1,
92
- Text = "Root",
93
- ParentIdValue = null,
94
- HasChildren = true,
95
- Icon = SvgIcon.Folder,
96
- IsChecked = false,
97
- IsActive = true
98
- });
91
+ {
92
+ Id = 1,
93
+ Text = "Root",
94
+ ParentIdValue = null,
95
+ HasChildren = true,
96
+ Icon = SvgIcon.Folder,
97
+ IsChecked = false,
98
+ IsActive = true
99
+ });
99
100
100
101
Random rnd = new Random();
101
102
for (int i = 2; i <= 5; i++)
102
103
{
103
104
bool hasChildren = rnd.Next(0, 2) == 1;
104
105
items.Add(new TreeViewItem()
105
- {
106
- Id = i,
107
- Text = $"Folder {i}",
108
- ParentIdValue = 1,
109
- HasChildren = hasChildren,
110
- Icon = hasChildren ? SvgIcon.Folder : SvgIcon.File,
111
- IsChecked = false,
112
- IsActive = rnd.Next(0, 2) == 1
113
- });
106
+ {
107
+ Id = i,
108
+ Text = $"Folder {i}",
109
+ ParentIdValue = 1,
110
+ HasChildren = hasChildren,
111
+ Icon = hasChildren ? SvgIcon.Folder : SvgIcon.File,
112
+ IsChecked = false,
113
+ IsActive = rnd.Next(0, 2) == 1
114
+ });
114
115
115
116
if (hasChildren)
116
117
{
117
118
for (int j = 1; j <= rnd.Next(1, 4); j++)
118
119
{
119
120
int childId = i * 10 + j;
120
121
items.Add(new TreeViewItem()
121
- {
122
- Id = childId,
123
- Text = $"File {childId}",
124
- ParentIdValue = i,
125
- HasChildren = false,
126
- Icon = SvgIcon.File,
127
- IsChecked = false,
128
- IsActive = rnd.Next(0, 2) == 1
129
- });
122
+ {
123
+ Id = childId,
124
+ Text = $"File {childId}",
125
+ ParentIdValue = i,
126
+ HasChildren = false,
127
+ Icon = SvgIcon.File,
128
+ IsChecked = false,
129
+ IsActive = rnd.Next(0, 2) == 1
130
+ });
130
131
}
131
132
}
132
133
}
@@ -137,10 +138,10 @@ To disable checkboxes for specific TreeView items based on a condition, use the
137
138
public class TreeViewItem
138
139
{
139
140
public int Id { get; set; }
140
- public string Text { get; set; }
141
+ public string Text { get; set; } = string.Empty;
141
142
public int? ParentIdValue { get; set; }
142
143
public bool HasChildren { get; set; }
143
- public ISvgIcon Icon { get; set; }
144
+ public ISvgIcon? Icon { get; set; }
144
145
public bool IsChecked { get; set; }
145
146
public bool IsActive { get; set; }
146
147
}
0 commit comments