This question is locked. New answers and comments are not allowed.
Hello and Happy Friday
In this example I have a gridview with expandable rows with a child. When the child grid opens, I would like to bind the "name" column's column header to the name from the parent row. Eg, open the "Actors" row, and the child's column header reads "Actors". Open the "Famous Dogs" row, and the child's column header reads "Famous Dogs".
I know I can hook into IsExpandedChanged and set the column header explicitly, but can I do this in a binding ?
Thanks for any advice -
Scott
In this example I have a gridview with expandable rows with a child. When the child grid opens, I would like to bind the "name" column's column header to the name from the parent row. Eg, open the "Actors" row, and the child's column header reads "Actors". Open the "Famous Dogs" row, and the child's column header reads "Famous Dogs".
I know I can hook into IsExpandedChanged and set the column header explicitly, but can I do this in a binding ?
<UserControl x:Class="RadDragDrop.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <StackPanel x:Name="LayoutRoot" Background="White"> <telerik:RadGridView Name="myToplevelGrid" ItemsSource="{Binding}" RowLoaded="myToplevelGrid_RowLoaded" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Category Name" DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn Header="Cumulative Value" DataMemberBinding="{Binding Value}" IsReadOnly="True" DataFormatString="{}{0:c}" /> </telerik:RadGridView.Columns> <telerik:RadGridView.ChildTableDefinitions> <telerik:GridViewTableDefinition> </telerik:GridViewTableDefinition> </telerik:RadGridView.ChildTableDefinitions> <telerik:RadGridView.HierarchyChildTemplate> <DataTemplate> <telerik:RadGridView Name="myChildGrid" AutoGenerateColumns="False" ItemsSource="{Binding Children}" RowLoaded="myChildGrid_RowLoaded" > <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name, Mode=TwoWay}" Background="LightGoldenrodYellow" Header="{Binding Parent.Name}" ***** What goes here ? /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Value, Mode=TwoWay}" Background="LightGoldenrodYellow" Header="Member Value" DataFormatString="{}{0:c}" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </DataTemplate> </telerik:RadGridView.HierarchyChildTemplate> </telerik:RadGridView> </StackPanel> </UserControl> using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using Telerik.Windows.Controls; using Telerik.Windows.Controls.GridView; namespace RadDragDrop { public partial class MainPage : UserControl { Random R = new Random(DateTime.Now.Second); public MainPage() { InitializeComponent(); myToplevelGrid.ItemsSource = MyDataModel(); } public class BusinessObject : ViewModelBase { public string Name { get; set; } public BusinessObject Parent { get; set; } public List<BusinessObject> Children { get; set; } private double myValue; public double Value { get { return myValue; } set { if (value != myValue) { myValue = value; OnPropertyChanged("Value"); } } } } public List<BusinessObject> MyDataModel() { int i = -1; List<BusinessObject> results = new List<BusinessObject>(); i++; results.Add(new BusinessObject() { Name = "Actors", Children = new List<BusinessObject>() }); results[i].Children.Add(new BusinessObject() { Name = "Angelina Jolie", Parent = results[i], Value = 1 }); results[i].Children.Add(new BusinessObject() { Name = "Brad Pitt", Parent = results[i], Value = 12 }); results[i].Children.Add(new BusinessObject() { Name = "Sylvester Stalone", Parent = results[i], Value = 123 }); results[i].Children.Add(new BusinessObject() { Name = "Cameron Diaz", Parent = results[i], Value = 1234 }); i++; results.Add(new BusinessObject() { Name = "Presidents", Children = new List<BusinessObject>() }); results[i].Children.Add(new BusinessObject() { Name = "George Washington", Parent = results[i], Value = 1 }); results[i].Children.Add(new BusinessObject() { Name = "Abraham Lincoln", Parent = results[i], Value = 2 }); results[i].Children.Add(new BusinessObject() { Name = "Grover Cleveland", Parent = results[i], Value = 3 }); results[i].Children.Add(new BusinessObject() { Name = "Linden Johnson", Parent = results[i], Value = 4 }); i++; results.Add(new BusinessObject() { Name = "Famous Dogs", Children = new List<BusinessObject>() }); results[i].Children.Add(new BusinessObject() { Name = "Lassie", Parent = results[i], Value = 5 }); results[i].Children.Add(new BusinessObject() { Name = "Rin Tin Tin", Parent = results[i], Value = 6 }); results[i].Children.Add(new BusinessObject() { Name = "Toto", Parent = results[i], Value = 7 }); results[i].Children.Add(new BusinessObject() { Name = "Hooch", Parent = results[i], Value = 8 }); i++; results.Add(new BusinessObject() { Name = "Cartoon Characters", Children = new List<BusinessObject>() }); results[i].Children.Add(new BusinessObject() { Name = "Ren & Stimpy", Parent = results[i], Value = 9 }); results[i].Children.Add(new BusinessObject() { Name = "Beavis & Butthead", Parent = results[i], Value = 8 }); results[i].Children.Add(new BusinessObject() { Name = "Pinky & The Brain", Parent = results[i], Value = 7 }); results[i].Children.Add(new BusinessObject() { Name = "Tom & Jerry", Parent = results[i], Value = 6 }); foreach (BusinessObject bo in results) bo.Value = (from values in bo.Children select values.Value).Sum(); return results; } private void myToplevelGrid_RowLoaded(object sender, RowLoadedEventArgs e) { if (e.Row.GetType() == typeof(GridViewHeaderRow)) return; if (e.Row.GetType() == typeof(GridViewFooterRow)) return; GridViewRow row = e.Row as GridViewRow; row.IsExpandable = true; } private void myChildGrid_RowLoaded(object sender, RowLoadedEventArgs e) { if (e.Row.GetType() == typeof(GridViewHeaderRow)) return; if (e.Row.GetType() == typeof(GridViewFooterRow)) return; GridViewRow row = e.Row as GridViewRow; foreach (GridViewCellBase cell in e.Row.Cells) if (cell.Column.Header.ToString() == "Member Value") { cell.LostFocus -= new RoutedEventHandler(cell_LostFocus); cell.LostFocus += new RoutedEventHandler(cell_LostFocus); } } void cell_LostFocus(object sender, RoutedEventArgs e) { List<BusinessObject> myList = myToplevelGrid.ItemsSource as List<BusinessObject>; foreach (BusinessObject bo in myList) bo.Value = (from businessObject in bo.Children select businessObject.Value).Sum(); } } } Thanks for any advice -
Scott