How to only allow edit mode for one node at a time?

I am looking for a way to make it so that when you enter edit mode for a node, all other nodes are not in edit mode. Basically, I want to avoid a situation where I have multiple nodes in edit mode like below. I've already tried programatically calling endedit on all nodes whenever I right click on a node to open context menu (that's how edit mode is entered)



5 Replies

VS Vijayarasan Sivanandham Syncfusion Team May 4, 2022 02:27 PM UTC

Hi Nour Douffir,

Your requirement can be achieved by using EditedItemTemplate in TreeViewAdv. Please refer the below code snippet,

<syncfusion:TreeViewAdv                 

            ItemsSource="{Binding ModelItems}"       >

                <syncfusion:TreeViewAdv.ItemTemplate>

                    <HierarchicalDataTemplate ItemsSource="{Binding Models}">

                        <TextBlock Text="{Binding Header}" />

                    </HierarchicalDataTemplate>

                </syncfusion:TreeViewAdv.ItemTemplate>

                <syncfusion:TreeViewAdv.EditedItemTemplate>

                    <HierarchicalDataTemplate ItemsSource="{Binding Models}">

                        <TextBox Text="{Binding Header,Mode=TwoWay}" />

                    </HierarchicalDataTemplate>

                </syncfusion:TreeViewAdv.EditedItemTemplate>

</syncfusion:TreeViewAdv>


UG Link: https://help.syncfusion.com/wpf/classic/treeview/customizing-data-templates#edit-template

Please find the sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S


Attachment: Sample_a0016e8b.zip


ND Nour Douffir May 4, 2022 03:55 PM UTC

Hi, I am using the SfTreeView, not the TreeViewAdv, sorry for the confusion. I don't see any EditedItemTemplate for the sftreeview.



VS Vijayarasan Sivanandham Syncfusion Team May 5, 2022 02:46 PM UTC

Hi Nour Douffir,

Your requirement to edit mode for single node at a time in SfTreeView can be achieved by defining the EditTemplate. Please refer the below code snippet,

<syncfusion:SfTreeView x:Name="treeView"

                               ItemsSource="{Binding Folders}"   

                               ChildPropertyName="Files"

                               AutoExpandMode="AllNodes"

                               AllowEditing="True"

                               ItemEndEdit="OnItemEndEdit"    >

            <syncfusion:SfTreeView.ItemTemplate>

                <DataTemplate>

                    <TextBlock Text="{Binding FileName}" VerticalAlignment="Center"/>

                </DataTemplate>

            </syncfusion:SfTreeView.ItemTemplate>

            <syncfusion:SfTreeView.EditTemplate>

                <DataTemplate>

                    <TextBox Text="{Binding FileName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"/>

                </DataTemplate>

            </syncfusion:SfTreeView.EditTemplate>

</syncfusion:SfTreeView>


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

Please find the sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S


Attachment: SfTreeViewDemo_64c8699f.zip


ND Nour Douffir May 10, 2022 02:40 PM UTC

Hi  Vijayarasan,

This still doesn't work. To clarify, I am initiating edit by using the item context menu as shown below:

<syncfusion:SfTreeView.ItemContextMenu>
                <ContextMenu>
                    <MenuItem Command="{x:Static syncfusion:TreeViewCommands.Edit}" CommandParameter="{Binding }">
                    </MenuItem>
                </ContextMenu>
</syncfusion:SfTreeView.ItemContextMenu>

I want to be able to end edit mode for the last node when I right click on a new node and select edit. As of right now, the only way to exit edit mode is to press enter. 

Thank You,

Nour



VS Vijayarasan Sivanandham Syncfusion Team May 11, 2022 02:16 PM UTC

Hi Nour Douffir,

We have prepared the simple sample based on a provided code snippet from our end. The reported issue is “End edit mode for the last node when I right-click on a new node in SfTreeView” and unable to replicate the issue from our end. It is working fine as expected. Please find the tested sample and video in the attachment.


Please have a look at this sample and let us know if we have missed any customization done in your application. Otherwise, try to reproduce the reported issue in this sample and revert to us with the modified sample and steps to replicate the issue. It will be more helpful for us to find the exact cause of the issue and to provide a prompt solution.

Regards,

Vijayarasan S


Attachment: Sample_And_Video_Demo_513fa2b4.zip

Loader.
Up arrow icon