This is a migrated thread and some comments may be shown as answers.

Header toggle button check all/uncheck all

6 Answers 779 Views
GridView
This is a migrated thread and some comments may be shown as answers.
sarag
Top achievements
Rank 1
sarag asked on 14 Feb 2011, 11:30 PM
Hi ,

I am using Telerik, Q3 2010, blend 4 vs 2010.
i am using RadGridview, i have 10 columns, in the header i have toggle button for all 10 columns, how can i know which column is checked and on checked i want to select all the cell checkbox in that particular coloumn
please check the attached image.

thanks
sarag

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Feb 2011, 03:45 PM
Hi sarag,

The recommended approach would be to expose boolean properties for each column in your business object and to bing the ToggleButtons' IsChecked properties to those boolean properties. In this way you will be able to retrieve the checked/ unchecked values of each button. Furthermore, you will ensure that even when scrolling, the state of those buttons will still be kept.
 

All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sarag
Top achievements
Rank 1
answered on 15 Feb 2011, 04:35 PM
Hi Maya,

Thanks for your quick response, my object is set up as they you said, but my question how can i capture the header click event so that i can set the ischecked property . my header is a toggle button.

thanks
sarag
0
Maya
Telerik team
answered on 15 Feb 2011, 04:45 PM
Hello sarag,

Is it not appropriate for you to handle the Checked event of the RadToggleButton ? 
 

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sarag
Top achievements
Rank 1
answered on 15 Feb 2011, 05:22 PM
yes i can do that but the problem is columns are generating dynamically at runtime, the below code will work for cell[0], but i need to do for the remaining 10 coloumns. i need to find some way to find what button is click. i need the index of the header coloum where header is toggle button please see the code

  
<Window x:Class="RadControlsWpfApp1.MainWindow"
Title="MainWindow" Height="350" Width="525" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<Grid>
<telerik:RadGridView HorizontalAlignment="Left" Margin="12,12,0,0"
Name="radGridView1" VerticalAlignment="Top" AutoGenerateColumns="False"
Loaded="radGridView1_Loaded" CanUserSortColumns="False" CanUserResizeColumns="False"
CanUserReorderColumns="False" CanUserFreezeColumns="False" ShowGroupPanel="False"
IsFilteringAllowed="False"
EditTriggers="CellClick"
/>
</Grid>
</Window>
using System;
using System.Collections.Generic;
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;
namespace RadControlsWpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
radGridView1.ItemsSource = WorklistData.GetWorklistData();
}
private void radGridView1_Loaded(object sender, RoutedEventArgs e)
{
int k = 5;
for (int i = 0; i < 50; i++)
{
var column = new GridViewDataColumn();
var toggleButton = new RadToggleButton
{
Width = 80,
Height = 60,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
//Content = new Image(),
Content = "Test- " + i,
};
toggleButton.Checked += toggleButton_Checked;
toggleButton.Unchecked += toggleButton_Unchecked;
column.Header = toggleButton;
column.DataMemberBinding = new Binding("IsSelected");
this.radGridView1.Columns.Add(column);
k++;
}
}
void toggleButton_Unchecked(object sender, RoutedEventArgs e)
{
// i need to know which header coloumn is selected based on
// i need to set checkbox.checked == false
}
void toggleButton_Checked(object sender, RoutedEventArgs e)
{
// i need to know which header coloumn is selected based on
// i need to set checkbox.checked == true
}
}
}
using System.Collections.ObjectModel;
namespace RadControlsWpfApp1
{
public class WorklistData
{
public static ObservableCollection<WorklistModel> GetWorklistData()
{
var worklistModels = new ObservableCollection<WorklistModel>();
for (int i = 1; i <= 30; i++)
{
var worklistModel = new WorklistModel
{
ReagentTipsLoaded = 0,
SampleTipsRequired = 393,
SampleTipsLoaded = 224,
DeepWellsRequired = 96,
DeepWellsLoaded = 96,
MixingWellsRequired = 10,
MixingWellsLoaded = 10,
LisSamples = i + "25",
KnownPacks = i + 2,
IsSelected = false,
};
worklistModels.Add(worklistModel);
}
return worklistModels;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RadControlsWpfApp1
{
public class WorklistModel
{
public int ReagentTipsLoaded
{
get;
set;
}
public int SampleTipsRequired
{
get;
set;
}
public int SampleTipsLoaded
{
get;
set;
}
public int DeepWellsRequired
{
get;
set;
}
public int DeepWellsLoaded
{
get;
set;
}
public int MixingWellsRequired
{
get;
set;
}
public int MixingWellsLoaded
{
get;
set;
}
public string LisSamples
{
get;
set;
}
public int KnownPacks
{
get;
set;
}
public bool IsSelected
{
get;
set;
}
}
}

0
Maya
Telerik team
answered on 18 Feb 2011, 04:24 PM
Hello sarag,

You may handle the Checked event as follows:

private void ToggleButton_Checked(object sender, RoutedEventArgs e)
        {
            var button = sender as ToggleButton;
            var headerCell = button.ParentOfType<GridViewHeaderCell>();
            var displayIndex = headerCell.Column.DisplayIndex;
 
        }

The displayIndex will give you the information for which column's header has been clicked.
 

All the best,
Maya
the Telerik team
0
sarag
Top achievements
Rank 1
answered on 18 Feb 2011, 05:17 PM
thanks maya that works for me.
Tags
GridView
Asked by
sarag
Top achievements
Rank 1
Answers by
Maya
Telerik team
sarag
Top achievements
Rank 1
Share this question
or