@@ -158,7 +158,7 @@ private void HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey
158158 else if ( ( e . Key is VirtualKey . Left or VirtualKey . Right or VirtualKey . Up or VirtualKey . Down )
159159 && ! IsEditing )
160160 {
161- var row = ( SelectionUnit is TableViewSelectionUnit . Row ? SelectionStartRowIndex : SelectionStartCellSlot ? . Row ) ?? - 1 ;
161+ var row = ( LastSelectionUnit is TableViewSelectionUnit . Row ? SelectionStartRowIndex : SelectionStartCellSlot ? . Row ) ?? - 1 ;
162162 var column = CurrentCellSlot ? . Column ?? - 1 ;
163163
164164 if ( row == - 1 && column == - 1 )
@@ -168,6 +168,11 @@ private void HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey
168168 else if ( e . Key is VirtualKey . Left or VirtualKey . Right )
169169 {
170170 column = e . Key is VirtualKey . Left ? ctrlKey ? 0 : column - 1 : ctrlKey ? Columns . VisibleColumns . Count - 1 : column + 1 ;
171+ if ( column >= Columns . VisibleColumns . Count )
172+ {
173+ column = 0 ;
174+ row ++ ;
175+ }
171176 }
172177 else
173178 {
@@ -612,11 +617,6 @@ internal void ClearFilters()
612617 }
613618 }
614619
615- private bool IsValidSlot ( TableViewCellSlot slot )
616- {
617- return slot . Row >= 0 && slot . Column >= 0 && slot . Row < Items . Count && slot . Column < Columns . VisibleColumns . Count ;
618- }
619-
620620 internal new void SelectAll ( )
621621 {
622622 if ( IsEditing )
@@ -703,7 +703,7 @@ private void DeselectAllCells()
703703
704704 internal void MakeSelection ( TableViewCellSlot slot , bool shiftKey , bool ctrlKey = false )
705705 {
706- if ( slot . Row < 0 || slot . Row >= Items . Count )
706+ if ( ! slot . IsValidRow ( this ) )
707707 {
708708 return ;
709709 }
@@ -725,13 +725,17 @@ internal void MakeSelection(TableViewCellSlot slot, bool shiftKey, bool ctrlKey
725725 }
726726 }
727727
728- if ( SelectionUnit is TableViewSelectionUnit . Row )
728+ if ( SelectionUnit is TableViewSelectionUnit . Row
729+ || ( LastSelectionUnit is TableViewSelectionUnit . Row && slot . IsValidRow ( this ) && ! slot . IsValidColumn ( this ) )
730+ || ( SelectionUnit is TableViewSelectionUnit . CellOrRow && slot . IsValidRow ( this ) && ! slot . IsValidColumn ( this ) ) )
729731 {
730732 SelectRows ( slot , shiftKey ) ;
733+ LastSelectionUnit = TableViewSelectionUnit . Row ;
731734 }
732735 else
733736 {
734737 SelectCells ( slot , shiftKey ) ;
738+ LastSelectionUnit = TableViewSelectionUnit . Cell ;
735739 }
736740 }
737741 else if ( ! IsReadOnly )
@@ -771,7 +775,7 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
771775 }
772776 }
773777
774- if ( ! IsReadOnly && IsValidSlot ( slot ) )
778+ if ( ! IsReadOnly && slot . IsValid ( this ) )
775779 {
776780 DispatcherQueue . TryEnqueue ( ( ) => SetCurrentCell ( slot ) ) ;
777781 }
@@ -787,7 +791,7 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
787791
788792 private void SelectCells ( TableViewCellSlot slot , bool shiftKey )
789793 {
790- if ( ! IsValidSlot ( slot ) )
794+ if ( ! slot . IsValid ( this ) )
791795 {
792796 return ;
793797 }
@@ -896,7 +900,7 @@ private void OnCellSelectionChanged()
896900
897901 internal async Task < TableViewCell > ScrollCellIntoView ( TableViewCellSlot slot )
898902 {
899- if ( _scrollViewer is null || ! IsValidSlot ( slot ) ) return default ! ;
903+ if ( _scrollViewer is null || ! slot . IsValid ( this ) ) return default ! ;
900904
901905 var row = await ScrollRowIntoView ( slot . Row ) ;
902906 var ( start , end ) = GetColumnsInDisplay ( ) ;
@@ -1007,7 +1011,7 @@ void ViewChanged(object? _, ScrollViewerViewChangedEventArgs e)
10071011
10081012 internal TableViewCell GetCellFromSlot ( TableViewCellSlot slot )
10091013 {
1010- return IsValidSlot ( slot ) && ContainerFromIndex ( slot . Row ) is TableViewRow row ? row . Cells [ slot . Column ] : default ! ;
1014+ return slot . IsValid ( this ) && ContainerFromIndex ( slot . Row ) is TableViewRow row ? row . Cells [ slot . Column ] : default ! ;
10111015 }
10121016
10131017 private ( int start , int end ) GetColumnsInDisplay ( )
0 commit comments