I have a grid column with a CheckBox which is defined as follows
<telGrid:GridViewColumn.CellTemplate> |
<DataTemplate> |
<CheckBox IsChecked="{Binding IsOK, Mode=TwoWay}" Click="CheckOKCmd_Click"/> |
</DataTemplate> |
</telGrid:GridViewColumn.CellTemplate> |
The problem I have is that the SelectionChanged is not fired if I'm clicking directly into the check box. Can anybody please tell me how to force the SelectionChanged event to be fired.
Thanks in advance
Uwe
11 Answers, 1 is accepted
SelectionChanged will be fired if this CheckBox is bound to row IsSelected property similar to our GridViewSelectColumn.
Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Can you please elaborate how to do it.

as I remember I've done something like this to make sure that the correct row is selected
private void CheckOKCmd_Click(object sender, RoutedEventArgs e)
{
GridViewRow row = ((CheckBox)sender).ParentOfType<
GridViewRow
>();
if (row != null)
row.IsSelected = true;
// your code
}
Hope this helps
Bye
Uwe

I forgot to mention i'm using MVVM and i've already bound the Click behaviour of checkbox with a Command. The command parameter brings the data of that row and not the instance of row or grid.
Is there a way to tackle this with MVVM?
if you use default silverlight gridview and add a template checkbox column with MVVM the selection changes in it (while you click on templated control) . It seems to be a telerik grid specific problem.

There are several way to tackle the problem but I would need some more information to determine which one is right for your scenario. I would like know if your data items have IsSelected property and what happens when the SelectClicked command is executed.
Thank you for your time.
Regards,
Milan
the Telerik team

In my scenario, the first column of the grid is templated checkbox. If that checkbox is checked the editing of the row is enabled, and when its unchecked the editing for the row gets disabled. As per this functionality everything is working smooth.
The problem arises when i click the templated column (e.g checkbox) the row selection doesnot get change.
The SelectClicked is fired and it brings the data item of the rows but the row selection doesnot changes. It only changes when i click some readonly column of the row (on templated column it doesnot change row selection on the telerik Grid) .
Updates:
You can verify this problem on telerik grid with first column as templated. you will see the selected row does not change
<telGrid:GridViewColumn.CellTemplate> |
<DataTemplate> |
<CheckBox IsChecked="{Binding IsOK, Mode=TwoWay}" Click="CheckOKCmd_Click"/> |
</DataTemplate> |
</telGrid:GridViewColumn.CellTemplate> |
A grid row can be selected when its IsSelected property is set to true, when its corresponding data item is added to the SelectedItems collection, or when its correspoding data item is set as SelectedItem. Your code has to perform one of those actions to mark an item/row as selected.
To select a row when the CheckBox of that row is checked you can follow Uwe's advise and manually select the corresponding row.
Another approach is to bind the IsSelected property of every row to the IsOk property as demonstrated here:
public
MainPage()
{
InitializeComponent();
this
.clubsGrid.RowLoaded +=
new
EventHandler<RowLoadedEventArgs>(clubsGrid_RowLoaded);
}
void
clubsGrid_RowLoaded(
object
sender, RowLoadedEventArgs e)
{
var row = e.Row
as
GridViewRow;
if
(row !=
null
)
{
var binding =
new
Binding(
"IsOk"
);
binding.Mode = BindingMode.TwoWay;
binding.Source = row.Item;
row.SetBinding(GridViewRow.IsSelectedProperty, binding);
}
}
Hope this helps.
Sincerely yours,
Milan
the Telerik team

Thanks for your constant support.
I feel you are not understanding my question, which might be due to my bad way of putting it.
I'll again explain what i'm i looking :
I'm using SL4 with MVVM and prism. My all commands are being binded in ViewModel, hence my template column command will also be executed in viewmodel. I'm not using "CellEditTemplate" for my editable columns as if i put a checkbox or button it requires 3 mouse clicks to execute the command on it. So i'm just using the "CellTemplate" and keeping the control in it in enable state and setting the readonly property false. by this i've achieved a single click execution of the control. I'm pasting my templated column code below
<
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
>
Now as you can see it in code there is no "CellEditTemplate" and just by using the "celltemplate", i'm giving the easiness to user to select the templated object (which in this case is now checkbox) with single click.
Now when i do this, the click command on the template column is binding properly and select event is firing, the problem is "Row selection" doesnot change. if i click on some other column of the same grid and that column is "readonly =true" the selection of row changes. I understand i can capture the clickevent in the codebehind and follow the Uwe's advice, but it will break my MVVM model and i dont want to capture it in the codebehind.
The grid is with single selection mode and user can check/uncheck any number of checkboxes he/she wants. The last row on which the action is performed by the user needs to be shown as highlight/selected.
The last solution provided to me is again in the code behind and i feel it will violate my single row selection mode.
I understand this post is getting longer but this problem needs to be resolved earliest. What i'm looking towards is a solution in "ViewModel and XAML" rather than
"codebehind and XAML"
Thanks

I've solved the problem in the following way:
<
telerikGridView:GridViewDataColumn
IsReadOnly
=
"False"
HeaderCellStyle
=
"{StaticResource GridViewHeaderCellStyle}"
>
<
telerikGridView:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
CheckBox
IsChecked
=
"{Binding IsSelected, Mode=TwoWay}"
Name
=
"mainchk"
Commands:Click.Command
=
"{Binding DataSource.SelectClicked,Source={StaticResource DataContextProxy}, Mode =TwoWay}"
Commands:Click.CommandParameter
=
"{Binding ElementName=mainchk}"
Click
=
"CheckBox_Click"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerikGridView:GridViewDataColumn.CellTemplate
>
</
telerikGridView:GridViewDataColumn
>
As you can see i'm passing the checkbox object in the commandparameter, on the server i can take the row out of this object method specified by Uwe. Thanks everyone for keeping this thread awake! If there is any other better way possible it will be my pleasure to know it.

xaml (partial):
<ToggleButton x:Name="toggleButton"
Style="{StaticResource ToggleButtonStyle}"
Click="toggleButton_Click"
Margin="0, 2" />
code (partial):
private void toggleButton_Click(object sender, RoutedEventArgs e)
{
this.parentRow.IsSelected = true;
}
Hope this helps...