blazor-devexpress-dot-blazor-dot-dxtreeview-dot-setnodeschecked-x28-system-dot-func-devexpress-dot-blazor-dot-itreeviewnodeinfo-system-dot-boolean-system-dot-boolean-x29.md
Checks or unchecks the specified nodes.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public void SetNodesChecked(
Func<ITreeViewNodeInfo, bool> predicate,
bool check
)
| Name | Type | Description |
|---|---|---|
| predicate | Func<ITreeViewNodeInfo, Boolean> |
A method delegate that specifies particular nodes.
| | check | Boolean |
true to check nodes; false to uncheck nodes.
|
Use the SetNodesChecked method to check or uncheck the specified nodes in code.
The following code snippet expands the specified node and checks all its child nodes:
@using TreeView.Data
<DxTreeView @ref="MyTreeView"
[email protected]
CheckMode="TreeViewCheckMode.Multiple">
<DataMappings>
<DxTreeViewDataMapping Text="Product"
Key="Id"
ParentKey="ParentId" />
</DataMappings>
</DxTreeView>
@code {
DxTreeView MyTreeView;
protected override void OnAfterRender(bool firstRender) {
base.OnAfterRender(firstRender);
if(firstRender) {
MyTreeView.SetNodeExpanded(n => n.Text == "Clothing", true);
MyTreeView.SetNodesChecked(n => n.Parent?.Text == "Clothing", true);
}
}
}
namespace TreeView.Data {
public class DataFlatSource {
public class ProductFlat {
public string Product { get; set; }
public int Id { get; set; }
public int ParentId { get; set; }
}
public static IEnumerable<ProductFlat> DataFlat => new List<ProductFlat>() {
new ProductFlat () { Product = "Bikes", Id = 1 },
new ProductFlat () { Product = "Components", Id = 2 },
new ProductFlat () { Product = "Clothing", Id = 3 },
new ProductFlat () { Product = "Mountain Bikes", Id = 4, ParentId = 1 },
new ProductFlat () { Product = "Road Bikes", Id = 5, ParentId = 1 },
new ProductFlat () { Product = "Touring", Id = 6, ParentId = 1 },
new ProductFlat () { Product = "Handlebars", Id = 7, ParentId = 2 },
new ProductFlat () { Product = "Bottom Brackets", Id = 8, ParentId = 2 },
new ProductFlat () { Product = "Brakes", Id = 9, ParentId = 2 },
new ProductFlat () { Product = "Chains", Id = 10, ParentId = 2 },
new ProductFlat () { Product = "Bib-Shorts", Id = 11, ParentId = 3 },
new ProductFlat () { Product = "Gaps", Id = 12, ParentId = 3 },
new ProductFlat () { Product = "Gloves", Id = 13, ParentId = 3 },
};
}
}
See Also