WPF 从树列表视图中删除了选定的行
本文关键字:删除 列表 视图 WPF | 更新日期: 2023-09-27 18:34:22
我有以下树列表视图:
<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>
我的问题是如何从树列表视图中删除选定的行。谢谢
查看如何:手动控制拖放帮助文章,该文章演示如何使用拖放相关事件自定义 TreeList 的拖放功能。
本文的主要思想 - 如果你的 TreeListControl 绑定到 some 集合:
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);
}
}
来自 DevExpress 代码示例数据库的完整示例项目。