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

SelectedItem and Binding

4 Answers 407 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sebastian Talamoni
Top achievements
Rank 1
Sebastian Talamoni asked on 20 Feb 2009, 08:15 AM

Hi, 
I am new to the WPF world but I am trying to use the RadGridView in a ViewModel (MVVM) architecture.

Normally al my ViewModels contain a SelectedProduct property which automatically enables other realted commands in the UI. (change,view, etc).


This is working perfectly in the included ListBox control:

<ListBox ItemsSource="{Binding Products}"

                    SelectedItem="{Binding SelectedProduct}"

                    DisplayMemberPath="Product.ProductName">

        </ListBox>

When trying the same in your Telerik RadGrid it fails my property setter never gets called.

     <telerik:RadGridView telerik:Theming.Theme="Vista"

                                       MultipleSelect="False"

                                       ItemsSource="{Binding Products}"  IsReadOnly="False"

                                       SelectedItem="{Binding SelectedProduct}"

                                       ColumnsWidthMode="Fill" AutoGenerateColumns="False">

                   <telerik:RadGridView.Columns>


The SelectionChanged event off course works and raises every time I click / move on another item but I am expecting my "SelectedProduct" property to be automatically updated (setter never called).


This SelectedProduct property get's called on the getter so actually it's used/read.


Looks like it's not using 2-way binding...


Any ideas what I am doing wrong?? 


4 Answers, 1 is accepted

Sort by
0
Accepted
Hristo Deshev
Telerik team
answered on 23 Feb 2009, 05:34 PM
Hello Sebastian Talamoni,

I just tried to replicate your scenario and created a view model that would expose Products and SelectedProduct properties. I then bound it to a grid control that has virtually the same definition as the one you pasted here, and everything went smoothly. Whenever I select an item in the RadGridView control, the SelectedProduct property changes, and a TextBlock bound to a subproperty of the selected product.

Here's my grid declaration:

<telerik:RadGridView Name="RadGridView1" Grid.Row="0" 
                     MultipleSelect="False" 
                     ItemsSource="{Binding Products}" 
                     IsReadOnly="False" 
                     SelectedItem="{Binding SelectedProduct}" 
                     AutoGenerateColumns="False"
    <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn UniqueName="Description"></telerik:GridViewDataColumn> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 
 

I even bound a ListBox to the SelectedProduct property -- its selection got synchronized with the one in RadGridView:

<ListBox ItemsSource="{Binding Products}" Grid.Row="1" 
            SelectedItem="{Binding SelectedProduct}" 
            DisplayMemberPath="Description"
</ListBox> 
 

The only think that can go wrong in your case is maybe your model failing to raise a PropertyChanged event in the SelectedProduct property setter. My model did not need that as property sets happen through the bidirectional bindings which use PropertyDescriptor ValueChanged events, and those are triggered and consumed by WPF automatically.

I am attaching my sample project for your reference. Can you reproduce your problem there? Or maybe provide additional detail that will help me reproduce the issue on my end. Thanks!

Kind regards,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sebastian Talamoni
Top achievements
Rank 1
answered on 24 Feb 2009, 01:56 PM
First of all thanks for the example. Indeed your example works as expected.

I've spent several hours trying to reproduce it without any luck.
Later, I've noticed that your DLL was newer than mine. 

Ok, your DLL version is :2008.3.1217.35
mine is older : 2008.3.1105.35

So, If i take your project remove your DLLs and add the official 2008.Q3 
It just fails like i've reported.

I will update my Telerik WPF version and probably it will work there..

Thanks again, 
Sebastian
0
Jordan
Telerik team
answered on 24 Feb 2009, 05:11 PM
Hi Sebastian,

Our latest public build is 2008.3.1217.

Best wishes,
Jordan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sebastian Talamoni
Top achievements
Rank 1
answered on 24 Feb 2009, 05:44 PM
Yes, exactly.

Now with the latest version works fine , thanks.

Tags
GridView
Asked by
Sebastian Talamoni
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Sebastian Talamoni
Top achievements
Rank 1
Jordan
Telerik team
Share this question
or