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

Databinding to Selected Cells collection

1 Answer 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 13 Feb 2012, 03:43 PM
Hi,

I have a RadGridView from which I have set up an EventTrigger using the MVVMLight EventToCommand object in order to trap the SelectionChanged event in my ViewModel. This works fine when I pass in the DataGrid as an object to the ViewModel. Below is my Trigger:
 
<i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
        <cmd:EventToCommand  CommandParameter="{Binding ElementName=RadGrid}" Command="{Binding SelectPriotityCommand}"  PassEventArgsToCommand="False"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

 

 

However when I use this pattern I then have to derive the object I am interested in from the SelectedCells collection of the Grid. Also I would rather not access the RadGridView from the ViewModel at all as this is difficult to Unit test. Therefore I would prefer to get a handle on the selected item in the collection from XAML. Should be simple! However if I substitute the CommandParemeter above with the following:

 

Binding ElementName='RadGrid', Path='SelectedCells[0].Item'}

 

Then I get the error

System.Windows.Data Error: Failed to connect to index '0' in object 'Telerik.Windows.Controls.GridView.Selection.CellInfoCollection' (type 'Telerik.Windows.Controls.GridView.Selection.CellInfoCollection'). BindingExpression: Path='SelectedCells[0].Item'

This seems to happen as soon as the page is loaded, am I simply getting this error as the collection is empty? How do I get this to work? I feel I must be missing something rather simple?

Regards,

Andy

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Feb 2012, 08:08 AM
Hi,

Maybe cells collection is empty (you do not have item at index 0) in your case?

Greetings,
Vlad 
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Andy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or