Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
545
How to set selected cells from code behind
posted

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