diff --git a/src/TableView.cs b/src/TableView.cs
index a07cd7e..5d29f14 100644
--- a/src/TableView.cs
+++ b/src/TableView.cs
@@ -130,7 +130,7 @@ protected override DependencyObject GetContainerForItemOverride()
_rows.Add(row);
return row;
}
-
+
///
protected override async void OnKeyDown(KeyRoutedEventArgs e)
{
@@ -652,7 +652,7 @@ private static TableViewBoundColumn GetTableViewColumnFromType(string? propertyN
{
column = new TableViewCheckBoxColumn();
}
- else if(type.IsUri())
+ else if (type.IsUri())
{
column = new TableViewHyperlinkColumn();
}
@@ -960,29 +960,20 @@ internal void MakeSelection(TableViewCellSlot slot, bool shiftKey, bool ctrlKey
{
ctrlKey = ctrlKey || SelectionMode is ListViewSelectionMode.Multiple;
- if (!ctrlKey || !(SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended))
- {
- if (SelectedItems.Count > 0)
- {
- DeselectAllItems();
- }
-
- if (SelectedCells.Count > 0)
- {
- SelectedCellRanges.Clear();
- }
- }
-
if (SelectionUnit is TableViewSelectionUnit.Row
|| (LastSelectionUnit is TableViewSelectionUnit.Row && slot.IsValidRow(this) && !slot.IsValidColumn(this))
|| (SelectionUnit is TableViewSelectionUnit.CellOrRow && slot.IsValidRow(this) && !slot.IsValidColumn(this)))
{
- SelectRows(slot, shiftKey);
+ if (!ctrlKey)
+ DeselectAllCells();
+ SelectRows(slot, shiftKey, ctrlKey);
LastSelectionUnit = TableViewSelectionUnit.Row;
}
else
{
- SelectCells(slot, shiftKey);
+ if (!ctrlKey)
+ DeselectAllItems();
+ SelectCells(slot, shiftKey, ctrlKey);
LastSelectionUnit = TableViewSelectionUnit.Cell;
}
}
@@ -996,34 +987,46 @@ internal void MakeSelection(TableViewCellSlot slot, bool shiftKey, bool ctrlKey
///
/// Selects rows based on the specified cell slot.
///
- private void SelectRows(TableViewCellSlot slot, bool shiftKey)
+ private void SelectRows(TableViewCellSlot slot, bool shiftKey, bool ctrlKey)
{
var selectionRange = SelectedRanges.FirstOrDefault(x => x.IsInRange(slot.Row));
SelectionStartRowIndex ??= slot.Row;
- CurrentRowIndex = slot.Row;
- if (selectionRange is not null)
+ if (selectionRange is not null && ctrlKey && !shiftKey && (CurrentRowIndex != slot.Row || CurrentCellSlot == slot))
{
- DeselectRange(selectionRange);
+ DeselectRange(new ItemIndexRange(slot.Row, 1));
}
-
- if (shiftKey && SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended)
+ else if ((!shiftKey && !ctrlKey && SelectedItems.Count <= 1) || SelectionMode is ListViewSelectionMode.Single)
+ {
+ SelectionStartRowIndex = CurrentRowIndex = SelectedIndex = slot.Row;
+ }
+ else if ((!ctrlKey && !shiftKey) || !(SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended))
+ {
+ SelectionStartRowIndex = CurrentRowIndex = SelectedIndex = slot.Row;
+ }
+ else if (SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended)
{
var min = Math.Min(SelectionStartRowIndex.Value, slot.Row);
var max = Math.Max(SelectionStartRowIndex.Value, slot.Row);
+ var newSelection = new ItemIndexRange(min, (uint)(max - min) + 1);
- SelectRange(new ItemIndexRange(min, (uint)(max - min) + 1));
- }
- else
- {
- SelectionStartRowIndex = slot.Row;
- if (SelectionMode is ListViewSelectionMode.Single)
+ if (!ctrlKey && newSelection.Length == 1)
{
- SelectedIndex = slot.Row;
+ SelectionStartRowIndex = CurrentRowIndex = SelectedIndex = slot.Row;
}
- else
+ if (selectionRange?.LastIndex > newSelection.LastIndex)
+ {
+ var deselectRange = new ItemIndexRange(newSelection.LastIndex + 1, (uint)(selectionRange.LastIndex - newSelection.LastIndex));
+ DeselectRange(deselectRange);
+ }
+ else if (selectionRange?.FirstIndex < newSelection.FirstIndex)
{
- SelectRange(new ItemIndexRange(slot.Row, 1));
+ var deselectRange = new ItemIndexRange(selectionRange.FirstIndex, (uint)(newSelection.FirstIndex - selectionRange.FirstIndex));
+ DeselectRange(deselectRange);
+ }
+ else if (selectionRange != newSelection)
+ {
+ SelectRange(newSelection);
}
}
@@ -1044,13 +1047,18 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
///
/// Selects cells based on the specified cell slot.
///
- private void SelectCells(TableViewCellSlot slot, bool shiftKey)
+ private void SelectCells(TableViewCellSlot slot, bool shiftKey, bool ctrlKey)
{
if (!slot.IsValid(this))
{
return;
}
+ if (!ctrlKey || !(SelectionMode is ListViewSelectionMode.Multiple or ListViewSelectionMode.Extended))
+ {
+ DeselectAll();
+ }
+
var selectionRange = (SelectionStartCellSlot is null ? null : SelectedCellRanges.LastOrDefault(x => SelectionStartCellSlot.HasValue && x.Contains(SelectionStartCellSlot.Value))) ?? [];
SelectedCellRanges.Remove(selectionRange);
selectionRange.Clear();
@@ -1514,4 +1522,5 @@ internal void UpdateHorizontalScrollBarMargin()
var offset = CellsHorizontalOffset + Columns.VisibleColumns.Where(c => c.IsFrozen).Sum(c => c.ActualWidth);
AttachedPropertiesHelper.SetFrozenColumnScrollBarSpace(_scrollViewer, offset);
}
-}
\ No newline at end of file
+}
+
diff --git a/src/TableViewCell.cs b/src/TableViewCell.cs
index a552d0c..758c3b1 100644
--- a/src/TableViewCell.cs
+++ b/src/TableViewCell.cs
@@ -224,7 +224,7 @@ protected override async void OnTapped(TappedRoutedEventArgs e)
if (e.Handled) return;
}
- if (TableView?.CurrentCellSlot != Slot)
+ if (TableView?.CurrentCellSlot != Slot || TableView?.LastSelectionUnit is TableViewSelectionUnit.Row)
{
MakeSelection();
e.Handled = true;
@@ -362,7 +362,6 @@ private void MakeSelection()
}
TableView.SetIsEditing(false);
- TableView.UpdateCornerButtonState();
}
///