How do you bind the selected row to the viewmodel? Microsoft grid has SelectedItem what is it for xamGrid?
Hi,
Our XamGrid currently does not provide this feature. However, we are planning to make some enhancements in that area in our upcoming 2011.1 Volume Release and provide the developer with the option to bind the Active Row implementing a property named ActiveItem.
HTH,
That sucks but thanks for the quick response. I can't wait for this functionality to come out.
In fact I needed to do the same thing.
I did a workaround that helped me to get the selected row in the viewmodel.
I will post 2 ways of doing it, 1 of them can only be used if you're using CSLA and BXF, the other one can be done without using them.
----------------------
Version1
XAML Code (CSLA + BXF version):
<my1:TriggerAction MethodName="MethodHandler" TargetControl="{Binding ElementName=ElementNameFiringEvent}" TriggerEvent="SelectedRowsCollectionChanged" />
In your case as it is the same as mine you should use that triggerevent.
Version2
Longer workaround without using csla + bxf:
<i:Interaction.Triggers> <i:EventTrigger EventName="SelectedRowsCollectionChanged" SourceName="ElementNameFiringEvent"> <ei:CallMethodAction MethodName="MethodHandler" TargetObject="{Binding}"/> </i:EventTrigger></i:Interaction.Triggers>
For this one you will need to add 2 references to your project:- Microsoft.Expression.Interactions- System.Windows.Interactivity
And add the corresponding namespace to the xaml file:----------------------
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Ok that's all for the XAML part.
ViewModel part
I did only this part as for using CSLA + BXF, if you're using the other version you will have to play a bit trying to get the params, etc.
VB.NET version:
Public Sub MethodHandler(ByVal sender As Object, ByVal e As ExecuteEventArgs) Dim event As SelectionCollectionChangedEventArgs(Of SelectedRowsCollection) = CType(e.TriggerParameter, SelectionCollectionChangedEventArgs(Of SelectedRowsCollection)) Dim row As SelectedRowsCollection = event.NewSelectedItems
'With this you would get first column value from first row, in my case selection mode in the grid is 'single Dim value As String = row.Item(0).Cells(0).Value.ToString() End Sub----------------------
That's it. Hope it works for you too :)
Note: You may have problems about not getting the viewmodel when firing the event, be sure to bind a viewmodel datacontext to the grid as it will look there.