Is it possible to programmatically select a record in a XamDataGrid in a viewmodel.
I've seen some posts how you can do this in the code behind of the xaml but i would prefer not to do that and select the record in my viewmodel.
Any help would be appreciated.
In order to programmatically select a record in your XamDataGrid from the ViewModel, I would recommend binding the SelectedDataItem or SelectedDataItems properties of the grid (depending on if you want single or multiple selection). Here is a documentation article about working with the Selected Data Items of the XamDataGrid.
Please let me know if you have any other questions or concerns on this matter.
Thank you I did figure out what I needed.
Although I do have another question but maybe I should create another post for it.
In my XamDataGrid I have two columns, the first is a checkbox and the second is just the name of an item in a list of items.
Everything is working so far. If I click the checkbox of a record in the grid my code works as expected.
What I want to be able to do is multiple select the checkboxes and have them check or uncheck but only if I'm selecting records in the first column where the checkbox is located. I don't want to check the checkboxes if I'm selecting in the second column of the data grid. Is that even possible?
I know that sounds like a lot but it would be nice if I could do that.
Again if I need to create a new post for this I understand.
Thank you for your update on this matter.
I am a little bit confused on your most recent update, though. Are you saying that you are only looking to be able to select records in this case with your checkbox column, and would not like the click on the other columns to do anything? If so, I have a few questions for you on this matter that, depending on the answer, may make this behavior simpler to achieve. Can you please provide some information on the following?
1. Are the other, non-checkbox columns editable or are they read-only?
2. Is your checkbox column bound to a property on your data item, or is it an unbound column?
3. Do you want to allow record activation on click of the other, non-checkbox columns? Note that “active” records are not the same as “selected” records. There can only be a single active record – it generally represents the currently “focused” record.
Sorry I didn't get back to this sooner. I think I found a different way of accomplishing what I wanted.
Having said that, just to let you know, what I was trying to do was find a way to check the checkboxes of multiple items in the XamDataGrid at the same time. I was trying to do this by using the mouse and using Shift+Click like you would to select multiple records at the same time in the grid.
It would be nice to check on checkbox then Shift+click another checkbox in the grid and then all the checkboxes in between would also become checked.
But like I said I think I found another way of doing this.
Thanks for your time.