Author Topic: WPF DataGrid Filtered DragSelection?  (Read 249 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4092
  • C3D user & customizer
WPF DataGrid Filtered DragSelection?
« on: March 18, 2024, 12:46:12 PM »
My DataGrid has a number of columns with varying types of data. In this example some are strings, one is for int, one for bool, and 2 for doubles. I am allowing multiselection and filtering the selection so only cells with the same type as the first selected cell can be selected. This is working fine, except when the user ends a drag selection when over a cell which is not supposed to be selected. The cell is not rendered with the selected color, but the cell border still indicates it is the current cell so if the user begins to type what he wants the cells changed to, the data entered is input to that invalid cell. That cell is not included in the DataGrid.SelectedCells property. So my question is, how can I force the grid to have the last valid selected cell be the one the user will be editing and not that cell which should not be edited?

I believe that I have tried setting each of the properties/methods which look like would handle this, all with zero success. I hope someone can tell me what I've missed.

I can provide the example project if needed.


Jeff_M

  • King Gator
  • Posts: 4092
  • C3D user & customizer
Re: WPF DataGrid Filtered DragSelection?
« Reply #1 on: March 18, 2024, 12:49:36 PM »
FYI, the misspelled Street items are intentional. I will be adding Spell check and Find/Replace tools later on.

Jeff_M

  • King Gator
  • Posts: 4092
  • C3D user & customizer
Re: WPF DataGrid Filtered DragSelection?
« Reply #2 on: March 27, 2024, 10:45:41 PM »
This nay not be the best way to accomplish what i need but it seems to do the job. Adding the MouseLeftButtonUp event with this code is all it took:
Code - C#: [Select]
  1.         private void PropData_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  2.         {
  3.             var dg = (DataGrid)sender;
  4.             if (dg.SelectedCells.Count >= 1)
  5.             {
  6.                 var cell = GetDataGridCell(dg.SelectedCells[dg.SelectedCells.Count - 1]);
  7.                 cell.Focus();
  8.             }
  9.         }
  10.