diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index d613283f66..08377e3b08 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -68,9 +68,11 @@ public: void UpdateCols( size_t pos, int numCols ); // Extend (or shrink) the current selection block (creating it if - // necessary, i.e. if there is no selection at all currently) to the one - // specified by the start and end coordinates of its opposite corners - // (which don't have to be in top/bottom left/right order). + // necessary, i.e. if there is no selection at all currently or if the + // current current cell isn't selected, as in this case a new block + // containing it is always added) to the one specified by the start and end + // coordinates of its opposite corners (which don't have to be in + // top/bottom left/right order). // // Note that blockStart is equal to wxGrid::m_currentCellCoords almost // always, but not always (the exception is when we scrolled out from diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index d4953c59d2..fc41b359bd 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -496,7 +496,11 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart, wxASSERT( blockStart.GetRow() != -1 && blockStart.GetCol() != -1 && blockEnd.GetRow() != -1 && blockEnd.GetCol() != -1 ); - if ( m_selection.empty() ) + // If selection doesn't contain the current cell (which also covers the + // special case of nothing being selected yet), we have to create a new + // block containing it because it doesn't make sense to extend any existing + // block to non-selected current cell. + if ( !IsInSelection(m_grid->GetGridCursorCoords()) ) { SelectBlock(blockStart, blockEnd); return true; @@ -649,7 +653,10 @@ wxGridCellCoords wxGridSelection::GetExtensionAnchor() const { wxGridCellCoords coords = m_grid->m_currentCellCoords; - if ( m_selection.empty() ) + // If the current cell isn't selected (which also covers the special case + // of nothing being selected yet), we have to use it as anchor as we need + // to ensure that it will get selected. + if ( !IsInSelection(coords) ) return coords; const wxGridBlockCoords& block = *m_selection.rbegin();