Wpf从treelistview中删除了选定的行

时间:2016-02-12 08:07:48

标签: c# wpf devexpress treelistview

我有以下树列表视图:

<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>

我的问题是如何从树列表视图中删除选定的行。 感谢

1 个答案:

答案 0 :(得分:0)

查看How to: Manually Control Drag and Drop帮助文章,该文章演示了如何使用与拖放相关的事件自定义TreeList的拖放功能。

本文的主要思想 - 如果您的TreeListControl绑定到某个集合:

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

您可以使用TreeListDragDropManager.Drop事件更改此集合中的某些项目(例如删除项目):

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.