This question is locked. New answers and comments are not allowed.
I am wondering if someone out there has some suggestions on how we can get our GridViewSelectColumn 100% working with the group checkboxes that we have added to our grid. It is working with the exception that if the particular group has rows that are not able to fit on the screen then they are not being selected.
The problem code is in here...even though if there are 100 rows in the group only those rows that are visible on the screen get checked because those that are not visible do not have a GridViewRow...
var row = groupRow.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow winds up empty...
Since I cannot post the solution here...these are the different parts that allow it to work
The Grid xaml
The GroupCheckBox
The GroupCheckBox C# code
The Grid and Methods
Anybody have any ideas on how I can make this work while still having the full functionality of the GridViewSelectColumn?
I will attach my
I appreciate any suggestions.
Thanks
Sandi
The problem code is in here...even though if there are 100 rows in the group only those rows that are visible on the screen get checked because those that are not visible do not have a GridViewRow...
var row = groupRow.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow winds up empty...
| public static void CheckUncheckRows(bool doCheck, GridViewGroupRow groupRow) |
| { |
| if (!_IsInSelectAllMode) |
| { |
| foreach (var item in groupRow.Items) |
| { |
| var row = groupRow.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow; |
| if (row != null) |
| { |
| row.IsSelected = doCheck; |
| } |
| } |
| } |
| } |
Since I cannot post the solution here...these are the different parts that allow it to work
The Grid xaml
| <grid:RadGridView Grid.Row="2" x:Name="FeatureAttributeDataGrid" |
| Margin="0" |
| MultipleSelect="True" |
| AutoGenerateColumns="False" |
| AutoExpandGroups="True" |
| ColumnsWidthMode="Auto" |
| CanUserFreezeColumns="True" |
| BorderThickness="0" > |
| <grid:RadGridView.GroupHeaderTemplate> |
| <DataTemplate> |
| <StackPanel Orientation="Horizontal" > |
| <local:GroupCheckBox /> |
| <TextBlock Text="{Binding Header}"/> |
| </StackPanel> |
| </DataTemplate> |
| </grid:RadGridView.GroupHeaderTemplate> |
| </grid:RadGridView> |
The GroupCheckBox
| <UserControl x:Class="TestGrouping.GroupCheckBox" |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| Width="16" Height="16"> |
| <Grid x:Name="LayoutRoot" Background="White"> |
| <CheckBox x:Name="PART_CheckBox" Click="PART_CheckBox_Click" /> |
| </Grid> |
| </UserControl> |
The GroupCheckBox C# code
| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Net; |
| using System.Windows; |
| using System.Windows.Controls; |
| using System.Windows.Documents; |
| using System.Windows.Input; |
| using System.Windows.Media; |
| using System.Windows.Media.Animation; |
| using System.Windows.Shapes; |
| using Telerik.Windows.Controls; |
| using Telerik.Windows.Controls.GridView; |
| using Telerik.Windows.Data; |
| namespace TestGrouping |
| { |
| public partial class GroupCheckBox : UserControl |
| { |
| public GroupCheckBox() |
| { |
| InitializeComponent(); |
| } |
| private void PART_CheckBox_Click(object sender, RoutedEventArgs e) |
| { |
| CheckBox chk = (CheckBox)sender; |
| GridViewGroupRow groupRow = chk.ParentOfType<GridViewGroupRow>(); |
| MainGrid.CheckUncheckRows((bool)chk.IsChecked, groupRow); |
| IList<GridViewGroupRow> grpRows = groupRow.ChildrenOfType<GridViewGroupRow>(); |
| MainGrid.CheckUncheckGroupRows((bool)chk.IsChecked, grpRows); |
| } |
| } |
| } |
The Grid and Methods
| public MainGrid() |
| { |
| this.FeatureAttributeDataGrid.AddHandler(GridViewCell.MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnGridMouseLeftButtonUp), true); |
| } |
| public static void CheckUncheckGroupRows(bool doCheck, IList<GridViewGroupRow> grpRows) |
| { |
| for (int i = 0; i < grpRows.Count; i++) |
| { |
| GridViewGroupRow grpRowChild = grpRows[i]; |
| IList<CheckBox> lstChk = grpRowChild.ChildrenOfType<CheckBox>(); |
| lstChk[0].IsChecked = doCheck; |
| CheckUncheckRows(doCheck, grpRowChild); |
| } |
| } |
| public static void CheckUncheckRows(bool doCheck, GridViewGroupRow groupRow) |
| { |
| if (!_IsInSelectAllMode) |
| { |
| foreach (var item in groupRow.Items) |
| { |
| var row = groupRow.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow; |
| if (row != null) |
| { |
| row.IsSelected = doCheck; |
| } |
| } |
| } |
| } |
| private void OnGridMouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
| { |
| _IsInSelectAllMode = true; |
| var senderElement = (FrameworkElement)e.OriginalSource; |
| var clickedCell = senderElement.ParentOfType<GridViewHeaderCell>(); |
| if (clickedCell != null) |
| { |
| CheckBox chkHeader = clickedCell.Column.Header as CheckBox; |
| if (chkHeader != null) |
| { |
| IList<GridViewGroupRow> grpRows = FeatureAttributeDataGrid.ChildrenOfType<GridViewGroupRow>(); |
| CheckUncheckGroupRows((bool)chkHeader.IsChecked, grpRows); |
| } |
| } |
| _IsInSelectAllMode = false; |
| } |
Anybody have any ideas on how I can make this work while still having the full functionality of the GridViewSelectColumn?
I will attach my
I appreciate any suggestions.
Thanks
Sandi