1

如何在 c# 中从 radTreeListView SelectedItems 集合中检索所有选中项目?

Retrieve All Checked Items下面的示例根本不起作用。

foreach ( object checkedItem in radTreeView.CheckedItems )
{
    // Get the container(RadTreeViewItem) of the checked item
    RadTreeViewItem container = radTreeView.ContainerFromItemRecursive( checkedItem );
    // Add your logic for handling the checked item scenario here
}

RadTreeListView 的 XML 是

<telerik:RadTreeListView x:Name="radTreeListView" ItemsSource="{Binding Items}" 
        AutoGenerateColumns="False" Grid.RowSpan="2" SelectionChanged="radTreeListView_SelectionChanged" SelectionMode="Extended" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectionChanging="radTreeListView_SelectionChanging" BeginningEdit="radTreeListView_BeginningEdit">
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
            </telerik:RadTreeListView.ChildTableDefinitions>
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewSelectColumn/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"   Header="Name" />
                </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
4

1 回答 1

2

SelectedItems是关键!

我按照此处所述准备了 SampleData并使用以下代码捕获检查的项目。

 System.Collections.ObjectModel.ObservableCollection<object> selected_items = radTreeListView.SelectedItems;
        foreach (object item in selected_items)
        {
            WarehouseItem warehouseitem = (WarehouseItem)item;
            MessageBox.Show(warehouseitem.Name);
        }
于 2013-11-04T07:19:20.287 回答