I have a behavior that changes cells in a column to edit mode when it becomes active.
If I am using the mouse to drag a selection of cells, as soon as I enter a cell that changes to edit mode, all the selection is lost.
Is there a way to maintain selection of all cells (including the cell that just changed to edit mode) when a cell changes to edit mode?
Hi rbccm,
Yes it is possible to maintain selection while a cell is in edit mode. However, you have to manually reselect the cell after edit mode as started. The expected behavior of the grid is that when edit mode is started, selection is cleared. You can change this by handling the EditModeStarting event on the XamDataGrid and resetting the Cell.IsSelected property on the previously selected cells. This will mean that you need to keep track of what cells were selected. Take a look at my attached sample. When you hold down the Ctrl key, it will allow you to drag select cells. You'll see that the currently activated cell enters edit mode, but the cell selection has not been lost.
This works for that use case, but does not handle the following use case:
Using the mouse to drag and select multiple cells, and having the cell change to edit mode when it activates.
When the cell EditStarting is called in that use case, none of the cells in the column with the cell going into edit mode are shown as selected.
There was a bug in my last sample where clicking on a cell did not deselect the already selected cells. I have resolved this in the new sample. I have also made some changes to when I am entering edit mode. Before I did it in the CellActivated event but this time I moved it to the SelectedItemsChanged event. This way I can keep using the built in drag selection functionality for determining which cells to select. The drag selection should function as it normally would when not entering edit mode.
Let me know if you have any further questions on this matter.
I was out on vacation the past 2 weeks. I will be looking at this in the next few days.
Hope you had a good vacation! If you have any questions please let me know.
Hi,
I continued to look for similar postings in the net and found following on stakeoverflow: https://stackoverflow.com/questions/17973652/xamdatagrid-selecteditems-empty-on-click-on-editable-cell
Using the EditModeStarting Event kept the SelectedDataItem ok, but lost it on ending the edit mode.
I started to use the ActiveDataItem instead and bound the SelectedDataItem in one way mode to highlight the selected row.
Niko
Hello Rob,
I was searching for this topic, tried to apply your second example but could not get it done. Maybe my question is slightly different - even when I don't see it.
A XamDataGrid is holding a number of columns, some of them are editable. They are XamComboEditor and a DateTimeEditor.
The SelectedDataItem is bound to the ViewModel and also set there.
<igDP:XamDataGrid Name="Auftraege" DataSource="{Binding Auftraege, UpdateSourceTrigger=PropertyChanged}" SelectedDataItemsScope="RecordsOnly" Grid.Column="0" Grid.Row="1" Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" GroupByAreaLocation="AboveDataArea" TabIndex="31" InitializeRecord="InitializeRecord" SelectedDataItem="{Binding CurrentAuftrag, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" EditModeStarting="xamDataGridAuftraege_EditModeStarting" PreviewMouseLeftButtonDown="xamDataGridAuftraege_PreviewMouseLeftButtonDown" SelectedItemsChanged="xamDataGridAuftraege_SelectedItemsChanged">
I would like to keep the SelectedDataItem unchanged during the editmode. At this point in time starting the editmode changes the SelectedDataItem.
As a second question: Is it also possible to keep the SelectedDataItem unchanged when using the filter fields? Does this even make sense from XamDataGrids concept?
What is the best way to achieve this?
Thanks
Have you had a chance to look at this yet? Let me know if you have any further questions.