I am using binding to ViewModels.
I am changing the state for the checkbox for each row, I have three rows.
Click on Row 1 and 2 to change the checkbox state and View Model is being updated fine.
Click on Row 3 to change state of checkbox and then click on another control on the form, problem is the binding Set call to VM for the change to the third row is not done and the viewmodel is not updated.
Is there a way to make sure that the last change on the thirs row get done when the gridview lostfocus.
I have a workaround but not pretty.
1. Add Event Handler for LostFocus on Grid
2. Call method I wrote to force update
private void roleGrid_LostFocus(object sender, RoutedEventArgs e)
{
RadGridView grid = (RadGridView)sender;
IterateVisualChild(grid);
}
private void IterateVisualChild(DependencyObject element)
{
try
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
var thing = VisualTreeHelper.GetChild(element, i);
if (VisualTreeHelper.GetChild(element, i) is System.Windows.Controls.CheckBox)
{
System.Windows.Controls.
CheckBox cb = VisualTreeHelper.GetChild(element, i) as System.Windows.Controls.CheckBox;
BindingExpression bindexp = cb.GetBindingExpression(CheckBox.IsCheckedProperty);
bindexp.UpdateSource();
continue;
}
if (VisualTreeHelper.GetChild(element, i) is Telerik.Windows.Controls.GridViewToggleButton)
{
Telerik.Windows.Controls.
GridViewToggleButton cb = VisualTreeHelper.GetChild(element, i) as Telerik.Windows.Controls.GridViewToggleButton;
BindingExpression bindexp = cb.GetBindingExpression(Telerik.Windows.Controls.GridViewToggleButton.IsCheckedProperty);
bindexp.UpdateSource();
continue;
}
IterateVisualChild(
VisualTreeHelper.GetChild(element, i));
}
}
catch (Exception ex)
{
}
}
<telerik:RadGridView
x:Name="roleGrid"
AutoGenerateColumns="False"
ItemsSource="{Binding Roles, Mode=TwoWay}"
SelectedItem="{Binding SelectedRole, Mode=TwoWay}"
VerticalAlignment="Top"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
AutoExpandGroups="True"
CanUserDeleteRows="False"
CanUserInsertRows="False" EditTriggers="CurrentCellClick"
RowDetailsTemplate="{StaticResource PermissionsTemplate}" RowDetailsVisibilityMode="Visible" LostFocus="roleGrid_LostFocus">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding RoleName}" Header="Role Name" IsReadOnly="True" />
<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsActive, Mode=TwoWay}" Header="Is Active" AutoSelectOnEdit="True" EditTriggers="CellClick" IsThreeState="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding RoleDescription}" Header="Role Description" IsReadOnly="True" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
This seems to work but is there an easier way to do this?
This looks like it is a common issue in general with silverlight.