Hi
I have a readonly xamgrid. I have bound my viewmodel class to the grid to populate data. What I want is to get the currently selected record or row index in my view model. Please kindly note I cannot make my grid editable.
Thanks,
Chev
Andrew, this was very helpful. However the set in the Viewmodel never gets called. I would like to be able to process the SelectedItems as they change. In other words I would like to create a private variable _selected and set its value and do some minor operation in there.
Using the code in your sample I would like to do something like:
public ObservableCollection<FoodClass> Selected
{
get { return _selected; }
set
_selected = value;
//do some stuff here
OnPropertyChanged("Selected");
}
but, as I said, the setter never gets called. Can you change the bevavior to do that?
Also the link you suggested for this kind of topics works but the link that from there should take you to the actual code does not.
Thanks. This helped me.
-Chev
Hello Chev,
Just checking in. Do you have any other questions or concerns?
Sincerely,AndrewDeveloper Support IInfragistics Inc.www.infragistics.com/support
One option to get the currently selected records in your view model using MVVM is to use a behavior to bind the currently selected records to a collection in your view model. You could also bind to the ActiveItem property.
In the attached sample that displays the first option above, the view model’s collection property named Selected is bound to the SelectedItems property of the custom behavior. The behavior gets the records of the row of the XamGrid that is selected and drops them into the Selected collection. I have bound that collection to a ListBox to provide a visual cue on how it is working.
For more about behaviors see: http://es.infragistics.com/community/blogs/devin_rader/archive/2011/06/01/using-behaviors-to-synchronize-selected-items-of-infragistics-silverlight-controls-to-a-viewmodel.aspx
Please let me know if you have any questions or concerns.