如何从radTreeListView SelectedItems集合中检索所有已检查的项目

时间:2013-11-04 07:04:59

标签: c# c#-4.0 telerik radtreeview

如何从c#中的radTreeListView SelectedItems集合中检索所有Checked Items?

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

1 个答案:

答案 0 :(得分:2)

SelectedItems是关键!

我按照here描述准备了SampleData,并使用以下代码捕获选中的项目。

 System.Collections.ObjectModel.ObservableCollection<object> selected_items = radTreeListView.SelectedItems;
        foreach (object item in selected_items)
        {
            WarehouseItem warehouseitem = (WarehouseItem)item;
            MessageBox.Show(warehouseitem.Name);
        }