help with treeview population

Hello, I've attached the code I'm working on.

Basically I'm trying to recreate the same as the example that I posted here: https://www.syncfusion.com/forums/171329/sftreegrid-exception-on-selection-in-edit-mode  BUT USING TREEVIEW control.

As you can see running the project the parent node not show.

As the prevoius example I would group the employes by ReportsTo property, and then drag and drop theme between the 2 viewmodels(like I done with treegridview in the example).

I don't understande where is my mistake.

Any advice?


Attachment: test_treeview_b4fa9a39.7z

5 Replies

VS Vijayarasan Sivanandham Syncfusion Team December 29, 2021 01:03 PM UTC

Hi Matteo,

We have checked the provided sample from our end. In your provided sample, you are created the self-relational collection and bound to the SfTreeView. The self-relational collection does not support in SfTreeView.

However, Your requirement can be achieved by to creating the nested or hierarchical collection (where each data object has hierarchy within) and bound to ItemsSource property of SfTreeView. Please find the sample demo in below link,

Sample Link: https://www.syncfusion.com/downloads/support/forum/171561/ze/SfTreeViewDemo2034396114

GitHub Sample Link:
https://github.com/syncfusion/wpf-demos/tree/master/treeview

For more information related to Data Population, please refer the below user guide documentation link, 

Regards, 
Vijayarasan S 



MA Matteo January 5, 2022 07:06 PM UTC

I've ported thi example:https://github.com/SyncfusionExamples/How-to-customize-tree-nodes-using-data-template-selector-in-wpf-treeview to VB.NET (.NET CORE 3.1) using Stylet MVVM Framework (https://github.com/canton7/Stylet ). Then I tryed to enable editmode adding:

 x:Name="sfTreeView" 
                               ItemsSource="{Binding Items}"    
                               ChildPropertyName="Files"
                               AutoExpandMode="RootNodes"
                               AllowEditing="True"
                               >
    
        
             Text="{Binding Name}" VerticalAlignment="Center"/>
        
    
    
        
             Text="{Binding Name}" 
					 VerticalContentAlignment="Center" 
                     Margin="-4,0,-4,0"
                     Height="{Binding ItemHeight,ElementName=sfTreeView}" />
        
    

as showed here: https://help.syncfusion.com/wpf/treeview/editing I can edit but when I press enter I lose the change. what am I missing?

Is it possible also to have multicolumn to show properties of the objects?



VS Vijayarasan Sivanandham Syncfusion Team January 6, 2022 04:57 PM UTC

Queries 
Solutions 
 
I can edit but when I press enter I lose the change. what am I missing? 
 

We suspect that in your application does not implement with the EditTemplateSelector in SfTreeView. So, You can resolve the reported problem by using EditTemplateSelector in SfTreeView. Please refer the below code snippet,

XAML Code Snippet:

 
<Window.Resources> 
        <DataTemplate x:Key="descriptionTemplate"> 
            <Grid x:Name="grid"> 
                <Grid Grid.Row="0"> 
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="20" /> 
                        <ColumnDefinition Width="*" /> 
                    </Grid.ColumnDefinitions> 
                    <Grid> 
                        <Image Source="{Binding Content.ImageIcon}" 
                                               VerticalAlignment="Center" 
                                               HorizontalAlignment="Center" 
                                               Height="16" 
                                               Width="16"/> 
                    </Grid> 
                    <Grid Grid.Column="1" 
                                              Margin="1,0,0,0" 
                                              VerticalAlignment="Center"> 
                        <Label Content="{Binding Content.ItemName}" 
                                                   Foreground="Black" 
                                                   FontSize="12" 
                                                   VerticalContentAlignment="Center" /> 
                    </Grid> 
                </Grid> 
            </Grid> 
        </DataTemplate> 
        <DataTemplate x:Key="headerTemplate"> 
            <Grid x:Name="grid"> 
                <Grid Grid.Row="0"> 
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="20" /> 
                        <ColumnDefinition Width="*" /> 
                    </Grid.ColumnDefinitions> 
                    <Grid> 
                        <Image Source="{Binding Content.ImageIcon}" 
                                               VerticalAlignment="Center" 
                                               HorizontalAlignment="Center" 
                                               Height="16" 
                                               Width="16"/> 
                    </Grid> 
                    <Grid Grid.Column="1" 
                                              Margin="1,0,0,0" 
                                              VerticalAlignment="Center"> 
                        <Label Content="{Binding Content.ItemName}" 
                                                   Foreground="Teal" 
                                                   FontSize="14" 
                                                   VerticalContentAlignment="Center" /> 
                    </Grid> 
                </Grid> 
            </Grid> 
        </DataTemplate> 
        <DataTemplate x:Key="editDescriptionTemplate"> 
            <Grid x:Name="grid"> 
                <Grid Grid.Row="0"> 
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="20" /> 
                        <ColumnDefinition Width="*" /> 
                    </Grid.ColumnDefinitions> 
                    <Grid> 
                        <Image Source="{Binding Content.ImageIcon}" 
                                               VerticalAlignment="Center" 
                                               HorizontalAlignment="Center" 
                                               Height="16" 
                                               Width="16"/> 
                    </Grid> 
                    <Grid Grid.Column="1" 
                                              Margin="1,0,0,0" 
                                              VerticalAlignment="Center"> 
                        <TextBox Text="{Binding Content.ItemName}" 
                                                   Foreground="Black" 
                                                   FontSize="12" 
                                                   VerticalContentAlignment="Center" /> 
                    </Grid> 
                </Grid> 
            </Grid> 
        </DataTemplate> 
        <DataTemplate x:Key="editHeaderTemplate"> 
            <Grid x:Name="grid"> 
                <Grid Grid.Row="0"> 
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="20" /> 
                        <ColumnDefinition Width="*" /> 
                    </Grid.ColumnDefinitions> 
                    <Grid> 
                        <Image Source="{Binding Content.ImageIcon}" 
                                               VerticalAlignment="Center" 
                                               HorizontalAlignment="Center" 
                                               Height="16" 
                                               Width="16"/> 
                    </Grid> 
                    <Grid Grid.Column="1" 
                                              Margin="1,0,0,0" 
                                              VerticalAlignment="Center"> 
                        <TextBox Text="{Binding Content.ItemName}" 
                                                   Foreground="Teal" 
                                                   FontSize="14" 
                                                   VerticalContentAlignment="Center" /> 
                    </Grid> 
                </Grid> 
            </Grid> 
        </DataTemplate> 
        <local:ItemTemplateSelector x:Key="itemTemplateSelector"/> 
        <local:EditTemplateSelector x:Key="editTemplateSelector" /> 
</Window.Resources> 
 
<syncfusion:SfTreeView x:Name="sfTreeView" Grid.Row="1" 
                               ChildPropertyName="SubFiles" 
                               FullRowSelect="True" 
                               AllowEditing="True" 
                               EditTrigger="DoubleTap" 
                               ItemTemplateDataContextType="Node" 
                               ItemsSource="{Binding ImageNodeInfo}"  
                               ItemTemplateSelector="{StaticResource itemTemplateSelector}"  
                               EditTemplateSelector="{StaticResource editTemplateSelector}" 
                               ItemHeight="28"  ExpanderWidth="20" IsAnimationEnabled="True">            
</syncfusion:SfTreeView> 
 
Is it possible also to have multicolumn to show properties of the objects? 

No. SfTreeView does not contains support to show multicolumn. However, Your requirement can be achieved by using TreeViewADV control.

For more information related to MultiColumnTreeView, please refer the below user guide documentation link,

 
 
 
 

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 



MA Matteo January 12, 2022 10:02 AM UTC

Thanks. I'm thinking that maybe I selected the wrong control.

My scenario is that: I have a collection/list of object with some properties.

I need to display some of this properties in the treegrid as multicolumn.

Need also drag and drop feature between 2 treegrid to move one object from one collection to another

Need    to  add "parent" node to "group" the item into user created "folders", and display different icon based on one specific property of the objects.

Need also to edit/delete add items at runtime by user interaction.

Should I use treeviewAdv?



VS Vijayarasan Sivanandham Syncfusion Team January 13, 2022 03:27 PM UTC

Hi Matteo,

Yes.
Please find answer for your queries below


 
Queries 
Solutions 
 
I have a collection/list of object with some properties. 
 

TreeViewAdv supports object binding.
For more information related to Populating with Data, please refer the below user guide documentation link, 
 


 
 
I need to display some of this properties in the treegrid as multicolumn. 

TreeView control can be created with multiple columns by setting the MultiColumnEnable property to true. For more information related to MultiColumnTreeView, please refer the below user guide documentation link,
 
 
 
 
Need also drag and drop feature between 2 treegrid to move one object from one collection to another 
 
 
TreeViewAdv control enables to drag TreeView items from one location to another. This is done by enabling the AllowDragDrop property. For more information related to Dragging TreeView, please refer the below user guide documentation link, 
 
 
Need    to  add "parent" node to "group" the item into user created "folders", and display different icon based on one specific property of the objects. 
 
 
TreeViewAdv control support to add images to the left and right corner. For more information related to Images, please refer the below user guide documentation link, 
 
 
Need also to edit items at runtime by user interaction. 
 
 
TreeViewAdv allow user to edit/non-edit the tree node items at runtime, by enable/disable IsEditable property. For more information related to Images, please refer the below user guide documentation link,

UG Link: https://help.syncfusion.com/wpf/classic/treeview/node-editing

 
 
Need also to delete add items at runtime by user interaction. 
 
 
Item can be removed by directly in underlying collection also using Remove () or RemoveAt (int index). The remove method can be used like below. 
 
private void OnRemoveFirstItemClicked(object sender, RoutedEventArgs e) 
{ 
            if (tree.Items.Count!=0) 
            { 
                tree.Items.Remove(tree.Items[0]); 
            } 
} 
 
 

Please let us know if you have any concerns in this.
 
 
Regards, 
Vijayarasan S 


Loader.
Up arrow icon