2016-02-12 45 views
0

我有下面的樹列表視圖:WPF刪除選定的行從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> 

我的問題是如何從樹形列表視圖中刪除所選的行。 謝謝

+2

正確的做法是使用數據綁定並從基礎數據源中刪除項目。 – Dennis

+0

這就是我想要做的,但我不知道該怎麼做。 –

+0

假設,'TreeListControl'是'ItemsControl',你需要綁定它的'ItemsSource'和一些'ObservableCollection',並從該集合中移除項目。如果你會發布代碼,你會如何填充項目,併發佈一個鏈接到'TreeListControl'描述。 – Dennis

回答

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.