Wpf deleted selected rows from treelistview

426 views Asked by At

I have the following tree list view:

<dxg:TreeListControl Name="treeList" Grid.Row="7" Height="230" Margin="10,2,10,0">
    <dxg:TreeListControl.Columns>
        <dxg:TreeListColumn FieldName="Description" />
        <dxg:TreeListColumn FieldName="Package" />
        <dxg:TreeListColumn FieldName="Procedure" />
    </dxg:TreeListControl.Columns>
    <dxg:TreeListControl.View>
        <dxg:TreeListView Name="treeListView" KeyFieldName="Id" ParentFieldName="ParentId" />
    </dxg:TreeListControl.View>
    <dxmvvm:Interaction.Behaviors>
        <dxg:TreeListDragDropManager x:Name="dragDropManager" AllowDrag="True" />
    </dxmvvm:Interaction.Behaviors>
</dxg:TreeListControl>

My question is how to delete the selected rows from the tree list view. Thanks

1

There are 1 answers

0
DmitryG On

Take a look at the How to: Manually Control Drag and Drop help-article that demonstrates how to customize Drag and Drop feature for the TreeList using Drag and Drop-related events.

The main idea of this article - if your TreeListControl is bound to the some collection:

treeList.ItemsSource = Stuff.GetStuff(); // ObservableCollection<Employee>

you can use the TreeListDragDropManager.Drop event to change some items from this collection (e.g. remove items):

void TreeListDragDropManager_Drop(object sender, 
    var employees = ((ObservableCollection<Employee>)treelist.ItemsSource);
    if(... some condition...){
        foreach (TreeListNode node in e.DraggedRows) {
            var employee = node.Content as Employee;
            employees.Remove(employee);
    }
}

The complete sample project from the DevExpress Code Examples database.