Hi!
I am trying to add "Ctrl + A" functionality to my XamDataGrid which is supposed to set all Cells to selected. I use a RelayCommand to trigger when "Ctrl + A" is pressed by the user. I also have a behavior which listens to SelectedItemsChanged and gets all selected the cells and sets them in a DependencyProperty I can bind to. I manged to set all Records to selected in code behind, which triggered my behavior event, but the selected cells collection was empty.
So, how do I set the XamDataGrid.SelectedItems.Cells collection programatically so I can get them in the event below?
This is my event in my behavior:
private void OnSelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e) { XamDataGrid dataGrid = (XamDataGrid) sender; SelectedCellCollection selected = dataGrid.SelectedItems.Cells; List<object> items = new List<object>(); foreach (Cell cell in selected) { items.Add(cell.Value); }
// Set the selected cell items in the depentency property SelectedItems = items;}
- Atle
Hello Atle,
Thank you for your post. I have been looking into and I can say that you can either use the SelectedItems’ Cells collection Add method in order to add Cells to the collection, so they become selected, or you can set each Cell’s IsSelected Property to true, which will also add the Cell to the SelectedItems’ Cells collection. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Thanks for the reply. I did end up using SelectedITems.Cells.Add, since setting Cell.IsSelected = true did not work for some reason.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.