or
<
Window
x:Class
=
"TestTreeListView.MainWindow"
xmlns:local
=
"clr-namespace:TestTreeListView"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:scm
=
"clr-namespace:System.ComponentModel;assembly=WindowsBase"
Name
=
"mainWindow"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.CommandBindings
>
<
CommandBinding
Command
=
"local:MainWindow.AddParentRow"
Executed
=
"AddParentRow_Executed"
/>
</
Window.CommandBindings
>
<
Window.Resources
>
<!-- The style of the expand button in the totally rad tree. -->
<
Style
x:Key
=
"ExpandButtonStyle"
TargetType
=
"{x:Type telerik:GridViewToggleButton}"
>
<
Setter
Property
=
"PresentationMode"
Value
=
"PlusMinus"
/>
</
Style
>
<!-- Context menu for adding a child row to a parent row. -->
<
ContextMenu
x:Key
=
"ParentRowContextMenu"
>
<
ContextMenu.CommandBindings
>
<
CommandBinding
Command
=
"local:MainWindow.AddChildRow"
Executed
=
"AddChildRow_Executed"
/>
</
ContextMenu.CommandBindings
>
<
MenuItem
Command
=
"local:MainWindow.AddChildRow"
/>
</
ContextMenu
>
<!-- A sorted view of the totally rad tree items. -->
<
CollectionViewSource
x:Key
=
"TotallyRadItemsView"
Source
=
"{Binding ElementName=mainWindow, Path=ParentItems}"
>
<
CollectionViewSource.SortDescriptions
>
<
scm:SortDescription
PropertyName
=
"Name"
/>
</
CollectionViewSource.SortDescriptions
>
</
CollectionViewSource
>
</
Window.Resources
>
<
Grid
>
<
telerik:RadTreeListView
Name
=
"totallyRadTreeListView"
AutoGenerateColumns
=
"True"
GridLinesVisibility
=
"None"
RowIndicatorVisibility
=
"Collapsed"
IsFilteringAllowed
=
"False"
CanUserSortColumns
=
"False"
HierarchyExpandButtonStyle
=
"{StaticResource ExpandButtonStyle}"
ScrollViewer.HorizontalScrollBarVisibility
=
"Disabled"
ItemsSource
=
"{Binding Source={StaticResource TotallyRadItemsView}}"
>
<
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:TreeListViewTableDefinition
ItemsSource
=
"{Binding ChildItems}"
/>
</
telerik:RadTreeListView.ChildTableDefinitions
>
<
telerik:RadTreeListView.ContextMenu
>
<!-- Context menu for adding a parent row. -->
<
ContextMenu
>
<
MenuItem
Command
=
"local:MainWindow.AddParentRow"
CommandTarget
=
"{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
/>
</
ContextMenu
>
</
telerik:RadTreeListView.ContextMenu
>
</
telerik:RadTreeListView
>
</
Grid
>
</
Window
>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView; // for RowLoadedEventArgs
using Telerik.Windows.Controls.TreeListView; // for TreeListViewRow
namespace TestTreeListView
{
/// <
summary
>
/// Interaction logic for MainWindow.xaml
/// </
summary
>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// RadTreeListView doesn't select its items on right-click, so add
// an event handler that accomplishes this.
mTreeItemClickHandler = new MouseButtonEventHandler( TotallyRadTreeListViewRow_MouseRightButtonDown );
totallyRadTreeListView.RowLoaded += new EventHandler<
RowLoadedEventArgs
>( TotallyRadTreeListView_RowLoaded );
totallyRadTreeListView.RowUnloaded += new EventHandler<
RowUnloadedEventArgs
>( TotallyRadTreeListView_RowUnloaded );
}
static MainWindow()
{
AddParentRow = new RoutedUICommand( "Add Parent Row", "AddParentRow", typeof( MainWindow ) );
AddChildRow = new RoutedUICommand( "Add Child Row", "AddChildRow", typeof( MainWindow ) );
}
public static RoutedUICommand AddParentRow { get; set; }
public static RoutedUICommand AddChildRow { get; set; }
public ObservableCollection<
ParentItem
> ParentItems { get { return mParentItems; } }
private void TotallyRadTreeListViewRow_MouseRightButtonDown( object sender, MouseButtonEventArgs e )
{
TreeListViewRow row = sender as TreeListViewRow;
row.IsSelected = true;
// Throws an exception when right-clicking a child row.
if ( row.ParentRow != null )
{
// use row.ParentRow.Item here
}
// Show the context menu whenever a parent row is clicked.
if ( row.Item is ParentItem )
{
ContextMenu menu = FindResource( "ParentRowContextMenu" ) as ContextMenu;
menu.IsOpen = true;
}
}
private void TotallyRadTreeListView_RowLoaded( object sender, RowLoadedEventArgs e )
{
if ( e.Row.Item != null )
{
e.Row.MouseRightButtonDown += mTreeItemClickHandler;
}
}
private void TotallyRadTreeListView_RowUnloaded( object sender, RowUnloadedEventArgs e )
{
e.Row.MouseRightButtonDown -= mTreeItemClickHandler;
}
private void AddParentRow_Executed( object target, ExecutedRoutedEventArgs e )
{
mParentItems.Add( new ParentItem() );
}
private void AddChildRow_Executed( object target, ExecutedRoutedEventArgs e )
{
ParentItem parentItem = totallyRadTreeListView.SelectedItem as ParentItem;
parentItem.ChildItems.Add( new ChildItem() );
}
private MouseButtonEventHandler mTreeItemClickHandler = null;
ObservableCollection<
ParentItem
> mParentItems = new ObservableCollection<
ParentItem
>();
}
public class ParentItem
{
public string Name { get { return name; } }
public ObservableCollection<
ChildItem
> ChildItems { get { return mChildItems; } }
private string name = "Parent" + i++;
ObservableCollection<
ChildItem
> mChildItems = new ObservableCollection<
ChildItem
>();
private static int i = 0;
}
public class ChildItem
{
public string Name { get { return name; } }
//public ObservableCollection<
ChildItem
> ChildItems { get { return mChildItems; } }
private string name = "Child" + i++;
//ObservableCollection<
ChildItem
> mChildItems = new ObservableCollection<
ChildItem
>();
private static int i = 0;
}
}
<
telerik:RadNumericUpDown
Name
=
"TopNSpinner"
IsEditable
=
"True"
Minimum
=
"1"
ValueFormat
=
"Numeric"
Value
=
"{Binding Result.TopNEventsCount, Mode=TwoWay}"
/>
TopNSpinner.NumberFormatInfo = new NumberFormatInfo() { NumberDecimalDigits = 0 };
System.Threading.Thread.Sleep(xxxx);
RadRichTextBox textBox =
new
RadRichTextBox();
grid.Children.Add(textBox);
textBox.ApplyTemplate();
textBox.UpdateEditorLayout();
textBox.Document =
this
.CreateDocument();
textBox.Print(
"MyDoc"
, PrintMode.Native);
// It crash in here!
IList<CheckBox> cbks = myGridView.ChildrenOfType<CheckBox>().ToList<CheckBox>();MyObject selectedProject = myGridView.SelectedItem as MyObject; int SelectedIndex = myGridView.Items.IndexOf(selectedProject);cbks[SelectedIndex].IsEnabled = True;
This works great, but except ChildrenOfType<>() only provides the rows for visible rows. I can not set EnableRowVirtualization to False.
How do I get the index of the visible row that is within the List of checkboxes (chks)?
Thanks in advance.