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

OneWay Binding of SelectedItem property

1 Answer 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 12 Apr 2011, 01:25 PM
I have a RadGridView bound to a CollectionViewSource and I'm experiencing the problem that the following code does not work while it works flawless with Selector Derived Controls:

var propertyName = ReflectionUtil.GetPropertyName(() => VM.SelectedDocument);
var binding = new Binding(propertyName) { Source = VM };
gridView.SetBinding(RadGridView.SelectedItemProperty, binding);

If I change the binding mode to TwoWay, it works but unfortunately that is not an option in this particular scenario.

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 Apr 2011, 06:41 PM

Hi Oliver,

If you apply the binding before the grid is first shown the binding will fail due to the current data binding mechanism of RadGridView. If you apply the binding in an event handler for the DataLoaded event you should see the binding take effect. 

For example:

private void gridView_DataLoaded_1(object sender, EventArgs e)
{
    var b = new Binding("SelectedItem") { Source = this };
    this.gridView.SetBinding(RadGridView.SelectedItemProperty, b);
}

Also, you should have in mind that if SelectedItem of the grid is set explicitly the binding will be lost. Such situation will occur if an item of the grid is clicked. 



Kind regards,
Milan
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
Oliver
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or