I am trying to implement 'check all' checkbox at header Silverlight RadGridView
Requirement:
When user checks the header checkbox of the RadGridView then all the check box of rows should get selected. However when a particular property or business specific of data, is false then that particular row checkbox shouldn't get checked.
Current implementation:
I have subclassed GridViewSelectColumn hoping that when user checks header checkbox telerik radgridview control only selects all enabled checkbox, but problem is it is selecting disabled checkbox as well.
Please advise.
Thanks,
Mahesh
public class MyGridViewSelectColumn : GridViewSelectColumn
{
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
var element = base.CreateCellElement(cell, dataItem);
var job = (JobDAO)dataItem;
var checkBox = element as CheckBox;
if (checkBox != null && job != null)
{
checkBox.SetBinding(CheckBox.IsEnabledProperty, new Binding { Source = job.IsSelectable, Mode = BindingMode.OneWay });
CheckBox.
}
return element;
}
protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
{
base.OnPropertyChanged(args);
}
}
Thanks,
Mahesh
15 Answers, 1 is accepted
private void gvJobs_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
foreach (var item in e.AddedItems)
{
if (!((model)item).IsSelectable)
{
this.radgrid.SelectedItems.Remove(item);
}
}
}
Thank you for the update. I am glad to hear that this solution works for you.
Please if you face any further difficulties do not hesitate to contact us.
Yoan
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
I need help. Your solution works for select all or selection. Now I need to removed the selected rows when user clicks on Unselect all checkbox (header checkbox).
Thanks,
Mahesh
I am sorry, but I am not sure that I can understand your scenario. May I ask you to elaborate a little bit more details on the exact use case you have? Do you want to "hide" the rows?
Looking forward to hearing from you!
Regards,
Yoan
Telerik
Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).
The solution you guys gave me its working fine when user clicks on select all checkbox. But when user clicks again on select all <gridviewselectcolumn> check box I need to de select the selected rows.
Thanks,
Mahesh
The reason for behavior of the SelectBox column is that, it isn't designed to bind data. The desired behavior can be achieved with a CheckBox column, by modifying the column header. Another benefit of the CheckBox column is that it provides better performance,when the underlying data is of a boolean type
I have attached a sample project demonstrating how create a CheckBox column with a behavior similar to the SelectBox column. Can you please inform me, if this solves your issue?
Regards,
Hristo
Telerik
Hi,
how can I check the Select All checkbox programaticaly? I would like that checkbox selected by default.
Thanks,
Laszlo
What you can do to check the select all CheckBox by default is to subscribe for example to its Loaded event. In the event handler, you can set the IsChecked property to true. For your convenience, I have modified the project from Hristo reply to demonstrate this approach.
Regards,
Dinko
Progress Telerik
Thanks Dinko, your very kind with your fast reply.
What I want to check programaticaly is the filter's Select All checkbox.
So I want all Filters distinct values to be selected when the user opens the filter.
Thank you for elaborating your scenario.
To check the SelectAll CheckBox in the Filter PopUp you can get first all popups in the RadGridView and subscribe to their Opened. You can check this Accessing the filtering popup help article which described how you can get the PopUp in the RadGridView. Then in the Opened event handler, you can get the FilteringControl from the Child property of the PopUp. Using its DataContext (FilteringViewModel) you can set the SelectAll bool property to true.
I have modified the project from my previous reply to demonstrate this approach.
Regards,
Dinko
Progress Telerik
Thanks Dinko
That is what I need, but I got 0 children with type GridViewHeaderCell, however my RadGridView has 5 columns.
do you think I missed something?
Thank you very much Dinko for your example.
That is what I need, but I got 0 items with type GridViewHeaderCell, however my RadGridView has 5 columns.
do you think i missed something?
Looking at the attached picture I am not sure what could be the reason behind this. You could get 0 items if you have set the ShowColumnHeaders property of the RadGridView control to False. Can you double check if this property is set and if yes you can set it to True.
Regards,
Dinko
Progress Telerik
Hi Dinko
I checked, the ShowColumnHeaders is True.
Maybe it is something around when I create the columns from code. See my attachment.
Thank you for your effort.
Laszlo
Looking at the provided picture it is not clear enough when you are adding the columns to the RadGridView. I have tested your scenario and it is working as expected on my side. I have modified the project from my previous reply. What I have changed is to subscribe to the loaded event of the MainWindow and add the column in the event handler. Can you take a look at this project and let me know how I can reproduce this on my side?
Regards,
Dinko
Progress Telerik