如何从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>
答案 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);
}