I'm looking for a datagrid control which can have a "select" checkbox in front of every row thats I'm sure isn't the issue. But I want it to behave such that when I check the checkbox that row should become editable. and I should be able to do that for every row in the datagrid. Multiple row editing upon multiple row selection through checkboxes is the main functionality requirement.
Can someone tell me if i can achieve such thing using telerik control, any sample for that matter will be highly appreciated.
8 Answers, 1 is accepted
The grid by default can edit only once cell however you can use CellTemplate to place for example TextBox and in this case you will get multiple cells editing.
Kind regards,Vlad
the Telerik team
I'm using CellTemplate for the checkbox. it does bind my data and show me the checkboxes against every row. But I'm facing problem while wiring up the commands to the checkbox.
<telerikGridView:RadGridView x:Name="gvMain" Margin="10" AutoGenerateColumns="False" SelectionMode="Extended" ItemsSource="{Binding Products}"> <telerikGridView:RadGridView.Columns> <telerikGridView:GridViewDataColumn IsReadOnly="False" > <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <StackPanel> <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Behaviors:RadGridCellClicked.Command="{Binding DataContext.SelectClicked}" /> </StackPanel> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Name, Mode=TwoWay}" IsReadOnly="True" /> <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Discontinued, Mode=TwoWay}" IsReadOnly="True" /> <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding LastUpdated, Mode=TwoWay}" IsReadOnly="True" /> </telerikGridView:RadGridView.Columns> </telerikGridView:RadGridView>thanks in advance.
The DataContext of the cells in RadGridView is different from the DataContext of RadGridView. You will need to define a Source for that Binding pointing to your ViewModel as a StaticResource. If you cannot expose your ViewModel as a StaticResource, you can use a DataContextProxy.
All the best,
Yavor Georgiev
the Telerik team
I used DataBindingProxy from the link you mentioned and now my commands are working just fine. I've also implemented a selectionchanged custom behavior for a grid its working as well although I don't know how can I access the "SelectedRadGridRow" object out of it and add some further customization to this control. Can you share any pointers for that matter?
You feedback is highly appreciated. Thanks in advance.
Could you share some more details, please? The source code for this behavior as well as a more thorough explanation of what you're trying to achieve would be quite helpful.
Kind regards,
Yavor Georgiev
the Telerik team
Hi,
I'm trying to customize RadGridView such that it has a customized
selectionColumn [a checkbox type column in front of every row.] by checking that checkbox makes that row
editable. I'm using PRISM and MVVM along with the telerik Controls so I don't
want to code in my code behind file.
Here is my sample xaml just to give you some idea.
<telerikGridView:RadGridView Name="dgxResults" IsReadOnly="True" ShowGroupPanel="False" IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Multiple" ItemsSource="{Binding Products}" AutoGenerateColumns="False" CommandExtension:RadGridItemSelected.Command="{Binding BehaviorCommand}" > <telerikGridView:RadGridView.Columns> <telerikGridView:GridViewDataColumn IsReadOnly="False" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" > <telerikGridView:GridViewDataColumn.CellTemplate > <DataTemplate> <StackPanel> <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Commands:Click.Command="{Binding DataSource.SelectClicked,Source={StaticResource DataContextProxy}, Mode =TwoWay}" Commands:Click.CommandParameter="{Binding}" /> </StackPanel> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> <telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" > <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <StackPanel> <TextBox Text="{Binding Name, Mode=TwoWay}" IsEnabled="{Binding IsSelected, Mode=TwoWay}" /> </StackPanel> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> <telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" > <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <StackPanel> <TextBox Text="{Binding Discontinued, Mode=TwoWay}" IsEnabled="{Binding IsSelected, Mode=TwoWay}" /> </StackPanel> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> <telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" > <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <StackPanel> <TextBox Text="{Binding LastUpdated, Mode=TwoWay}" IsEnabled="{Binding IsSelected, Mode=TwoWay}" /> </StackPanel> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> </telerikGridView:RadGridView.Columns> </telerikGridView:RadGridView> So far I've used cellTemplate and I used DataBindingProxy to bind commands from the viewmodel that works just fine. Then I've to implement a commandBehavior for RadGridView SelectionChanged as I need to know my SelectedItem.
Here is my code for that:
public static class RadGridItemSelected { public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached( "Command", typeof(ICommand), typeof(RadGridItemSelected), new PropertyMetadata(OnSetCommandCallback)); private static readonly DependencyProperty ItemSelectedCommandBehaviorProperty = DependencyProperty.RegisterAttached( "ItemSelectedCommandBehavior", typeof(GridViewItemSelectedCommandBehavior), typeof(RadGridItemSelected), null); public static void SetCommand(RadGridView outlookBar, ICommand command) { outlookBar.SetValue(CommandProperty, command); } public static ICommand GetCommand(RadGridView radGridView) { return radGridView.GetValue(CommandProperty) as ICommand; } private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { var radGridView = dependencyObject as RadGridView; if (null!=radGridView) { var behavior = GetOrCreateBehavior(radGridView); behavior.Command = e.NewValue as ICommand; } } private static GridViewItemSelectedCommandBehavior GetOrCreateBehavior(RadGridView radGridView) { var behavior = radGridView.GetValue(ItemSelectedCommandBehaviorProperty) as GridViewItemSelectedCommandBehavior; if (null==behavior ) { behavior = new GridViewItemSelectedCommandBehavior(radGridView); radGridView.SetValue(ItemSelectedCommandBehaviorProperty, behavior); } return behavior; } } public class GridViewItemSelectedCommandBehavior : CommandBehaviorBase<RadGridView> { public GridViewItemSelectedCommandBehavior(RadGridView radGridView) : base(radGridView) { radGridView.SelectionChanged += (s, e) => SelectionChanged(s, e); } void SelectionChanged(object sender, SelectionChangeEventArgs e) { if (null!=e && e.AddedItems.Count > 0) { CommandParameter = e.AddedItems[0]; ExecuteCommand(); } } }Now I'm facing two main show stoppers here.
First one is an unexpected GridSelection Behavior i.e. my Grid selection doesn't get invoked when I click on the checkbox [i.e. from the celltemplate of my grid control] whereas it work just fine when I click
On the other cells or the same even the same cell other than checkbox itself for that matter. Can't figure out what I'm doing wrong here or what should I do to make my CellTemplated CheckBox to make the SelectionChanged event work for this as well.
The 2nd part is related accessing the RadGridRow Object of my the grid at the time of SelectedChanged event. That is because I need to manipulate the cells and gridrows based on the data within them. So I expect some instance
of the RadgridRow itself or the Grid row. And I don't know how and where I can have such object of RadGridView while using PRISM.
I hope you get my scenario. Your help is much appreciated.
Regards,
The problem I mention about the checkbox click not firing the SelectionChanged event seems to be the problem with telerikgrid only. I've tried native datagrid with same markup and that seems to work just fine. i.e. cellTemplated checkbox click within silverlight datagrid row does fire the SelectionChange event. Is there any workaround for that in telerik?
and do answer the 2nd part as well.
Thanks in advance.
best regards,
This binding does not work because IsSelected is a property of GridViewRow, but bindings in cells are applied against the row's data item instead. You should use GridViewSelectColumn, which presents a CheckBox that, when checked, toggles the row selected state.
We do not support editing data programatically through GridView objects such as cells and rows. When SelectionChanged fires, you can access the selected item through the SelectedItem property of RadGridView, or SelectedItems if you have enabled multiple item selection. You can then proceed to manipulate its properties directly.
Greetings,
Yavor Georgiev
the Telerik team
