Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions src/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
_rows.Add(row);
return row;
}

/// <inheritdoc/>
protected override async void OnKeyDown(KeyRoutedEventArgs e)
{
Expand Down Expand Up @@ -588,7 +588,7 @@
}
else
{
foreach (var propertyInfo in dataType.GetProperties())

Check warning on line 591 in src/TableView.cs

View workflow job for this annotation

GitHub Actions / build

'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'WinUI.TableView.Extensions.ObjectExtensions.GetItemType(IEnumerable)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
{
var displayAttribute = propertyInfo.GetCustomAttributes().OfType<DisplayAttribute>().FirstOrDefault();
var autoGenerateField = displayAttribute?.GetAutoGenerateField();
Expand Down Expand Up @@ -652,7 +652,7 @@
{
column = new TableViewCheckBoxColumn();
}
else if(type.IsUri())
else if (type.IsUri())
{
column = new TableViewHyperlinkColumn();
}
Expand Down Expand Up @@ -960,29 +960,20 @@
{
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;
}
}
Expand All @@ -996,34 +987,46 @@
/// <summary>
/// Selects rows based on the specified cell slot.
/// </summary>
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);
}
}

Expand All @@ -1044,13 +1047,18 @@
/// <summary>
/// Selects cells based on the specified cell slot.
/// </summary>
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();
Expand Down Expand Up @@ -1514,4 +1522,5 @@
var offset = CellsHorizontalOffset + Columns.VisibleColumns.Where(c => c.IsFrozen).Sum(c => c.ActualWidth);
AttachedPropertiesHelper.SetFrozenColumnScrollBarSpace(_scrollViewer, offset);
}
}
}

3 changes: 1 addition & 2 deletions src/TableViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,7 +362,6 @@ private void MakeSelection()
}

TableView.SetIsEditing(false);
TableView.UpdateCornerButtonState();
}

/// <summary>
Expand Down
Loading