The Documentation has the following not under the CheckBox section for sfTreeView:-
" Programmatically adding or removing the node value not affects their parent and child nodes checkbox state. "
A bit of testing bears this out. If I add an item to the CheckedItems collection it selects that item in the TreeView but does not affect child or parent nodes. However, in a Treeview whose CheckBoxMode is recursive, I want it to affect the parents and children. How do I achieve this?
I've tried traversing the underlying itemsource programmatically and adding items to the CheckedItems collection. This works for children because they get set to a Checked stated. However, it doesn't really work for parents because these need to be set to intermediate and there doesn't seem to be a way to do that.
Hi Declan Hillier,
As you said in the previous update, the reported problem is not an issue. This
is the expected behavior in SfTreeView. We have mentioned this limitation in
our user documentation. Refer to the below user guide documentation link:
UG Link: https://help.syncfusion.com/wpf/treeview/checkbox#checkbox-state
Screenshot for your reference
We have checked the feasibility of achieving your requirement. We regret to let
you know that there is no other way to reflect the parent node checkboxes state
when programmatically updating the CheckedItems collection in SfTreeView.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
Ouch. That's a real blow and and is a show stopper for my particular use case. I'm using the tree to configure a model and it works perfectly while the user is doing the configuring. However, the configuration can then be saved and reloaded. When reloading there's no user interaction. The selected items are read from a file and have to be pushed to the tree programmatically. I don't think there's any way I can avoid that.
Is this a shortcoming you're likely to address in the future? It seems like a pretty big gap. I can probably switch to using a different control but it seems a shame because a treeview is very natural fit for the hierarchical data structure I need to support.
Declan
Hillier,
As we mentioned earlier, the reported scenario is the expected behavior of
SfTreeView. However, we will check the feasibility of implementing the
requested feature and update you with further details on February 27, 2023. We
appreciate your patience until then.
Declan Hillier,
Currently, SfTreeView does not have support to affect parent and child node checkbox state when programmatically adding/removing the node in CheckedItems. We have analyzed and considered your requirement of “Provide support to affect parent and child node checkbox state when programmatically adding/removing the node” in SfTreeView and logged a feature request for the same. We will implement this feature in any of our upcoming releases.
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.
Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.
Feedback link: https://www.syncfusion.com/feedback/41581/provide-support-to-affect-parent-and-child-node-checkbox-state-when
If you have any more specifications/suggestions for the feature request, you can
add them as a comment in the portal and cast your vote to make it count.
Thank you for raising the feature request. I'll keep my fingers crossed :)
Declan Hillier,
We are glad to announce the release of our Essential Studio 2023 Volume 3 Main Release V23.1.36. This update includes support for updating the checked states of parent and child nodes when items are added programmatically to the TreeView.CheckedItems. The update is now available for download at the following link.
We would also like to inform you that the checkbox states will be correctly updated when the NodePopulationMode is set to Instant, even if the CheckedItems contains the non-visible node. This is because in Instant mode, all nodes are created during the initial loading. However, when the NodePopulationMode is set to OnDemand, the checkbox state will only be updated for visible nodes. Additionally, the checkbox state will not be updated if the TreeView.CheckedItems contains non-visible nodes, as those nodes are only created on demand.
<syncfusion:SfTreeView x:Name="treeView" CheckBoxMode="Recursive" NodePopulationMode="Instant" ItemTemplateDataContextType="Node" ChildPropertyName="Models" ItemsSource="{Binding Items}" > <syncfusion:SfTreeView.ItemTemplate> <DataTemplate> <Grid> <CheckBox x:Name="CheckBox" FocusVisualStyle="{x:Null}" IsChecked="{Binding IsChecked, Mode=TwoWay}" /> <TextBlock FontSize="12" VerticalAlignment="Center" Text="{Binding Content.Header}" Margin="25,0,0,0"/> </Grid> </DataTemplate> </syncfusion:SfTreeView.ItemTemplate> </syncfusion:SfTreeView> |
private void OnCheckedItemsAddClicked(object sender, RoutedEventArgs e) { var viewModel = (this.DataContext as ViewModel); treeView.CheckedItems.Add(viewModel.Items[0].Models[1]); } |
We appreciate your support and thank you for your patience while waiting for this release. Please feel free to contact us if you require any further assistance.