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

[Solved] Issue with UpdateSource on Binding Grid

1 Answer 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eric
Top achievements
Rank 1
Eric asked on 20 Sep 2010, 03:08 PM
So I have a raggridview with a checkbox as one of the columns.

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.

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 23 Sep 2010, 09:41 AM
Hello Eric,

I tried to reproduce the issue you specified using the provided code-snippet. However, I was not able to. I am sending you the sample project I used for reproducing the problem so that you can use it as a reference and verify it there is some misunderstanding according to your requirements. Please feel free to change it in the way you need. 
Furthermore, RadGridView provides a Property - ActionOnLostFocus that may be set to - CommitEdit(the default value), CancelEdit and None. You may experiment  with them and test if it may be useful for your project. However, you have to keep in mind that in case of failure of validation, the changes will not be committed. 
 

Kind regards,
Maya
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
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or