Deleting Rows and controlling the selected Node.

I have an app with a GridTreeNode that is populated via a viewmodel. The xamL used is

    <syncfusion:GridTreeControl x:Name="_tree" 
        AutoPopulateColumns="False"
AllowDrop="False"
AllowSort="False"
ChildPropertyName="Children"
EnableHotRowMarker="False"
EnableNodeSelection="True"
        UpdateMode="PropertyChanged"
ItemsSource="{Binding FHIRModelNodes}"
NotifyPropertyChanges="True"
VisualStyle="Metro"
syncfusion:LayoutControl.SetMetroMode="True" 
        ExpandGlyphType="PlusMinusLines" 
        SupportNodeImages="True" 
        Width="490" AllowAutoSizingNodeColumn="False" 
        ExpandStateAtStartUp="AllNodesExpanded">

I need to be able too delete the selected node (the GridTree is set to single row selection). I'm not sure if I am doing this correctly, the way I delete the node is directly from the viewmodel. This nearly works the problem is that as I have deleted the "selected node" the control the makes another node selected.

I need to be able to set the selected node by code. I have tried doing this by using code along the lines of :

_myGridTree.SelectedNode =_theNodeIwant;

Although this appears to work and the intended node is selected, I end up with two nodes selected (even though the control is set to single row selection). I guess I must be doing it wrong.

So a few questions.

1) How do you unselect all nodes by code
2) What is the correct way to delete a node (and have this reflected back into the viewmodel)
3) I am assuming the way to specify the node I want to be selected is as per http://www.syncfusion.com/forums/121500/setting-selected-node 

thanks



3 Replies

JS Jayapradha S Syncfusion Team March 31, 2016 12:36 PM UTC

Hi Richard,

Thank you for contacting Syncfusion Support.


We have analyzed your queries and please find the details below,

Regarding Query: How do you unselect all nodes by code

You can deselect all the nodes by clearing the SelectedNodes as below,
Code Example:
treeGrid.InternalGrid.SelectedNodes.Clear();

Regarding Query: What is the correct way to delete a node (and have this reflected back into the viewmodel)

You can delete a node from treegrid and able to delete that node from view model also,
Code Example:

var viewModel = this.treeGrid.DataContext as ViewModel;

           

if (treeGrid.SelectedNodes.Count == 0)

    return;


var node = treeGrid.SelectedNodes[0];           

viewModel.PersonDetails.Remove(node.Item as PersonInfo);

foreach(var person in viewModel.PersonDetails)

{

    person.Children.Remove(node.Item as PersonInfo);

}


We have prepared a sample for your requirement and please find the sample from the below location,
Sample link: http://www.syncfusion.com/downloads/support/forum/123557/ze/GridTreeControl-1907522355

Regarding Query: I am assuming the way to specify the node I want to be selected is as per http://www.syncfusion.com/forums/121500/setting-selected-node 
Yes. You can select a specific node by adding a node to TreeGrid.InternalGrid.SelectedNodes as explained in the above forum.


Regards,
Jayapradha



RI Richard March 31, 2016 11:29 PM UTC

Thanks for the assistance, I have just about got it working now.

I have a slight problem in that after I "deselect" the selected nodes using the code suggested:

        _controlModelTree.InternalGrid.SelectedNodes.Clear();

The "row selection" is removed as desired, but there seems to be some form of "cell" selection, marked with a light blue border how do I get rid of that?
The image has the tree before delete on the right and after delete on the left.




JS Jayapradha S Syncfusion Team April 1, 2016 11:21 AM UTC

Hi Richard,

You can clear the current cell border while clearing the selected nodes by using the below code example,

Code Example:

treeGrid.InternalGrid.SelectedNodes.Clear();
treeGrid.InternalGrid.CurrentCell.Deactivate();


Regards,
Jayapradha

Loader.
Up arrow icon