diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index fb478b339d..55de239323 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -749,7 +749,8 @@ wxArrayInt wxGridSelection::GetRowSelection() const { for ( int r = block.GetTopRow(); r <= block.GetBottomRow(); ++r ) { - uniqueRows.Add(r); + if ( uniqueRows.Index(r) == wxNOT_FOUND ) + uniqueRows.Add(r); } } } @@ -779,7 +780,8 @@ wxArrayInt wxGridSelection::GetColSelection() const { for ( int c = block.GetLeftCol(); c <= block.GetRightCol(); ++c ) { - uniqueCols.Add(c); + if ( uniqueCols.Index(c) == wxNOT_FOUND ) + uniqueCols.Add(c); } } } diff --git a/tests/controls/gridtest.cpp b/tests/controls/gridtest.cpp index 3649985b36..34d4a925c5 100644 --- a/tests/controls/gridtest.cpp +++ b/tests/controls/gridtest.cpp @@ -901,6 +901,12 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SelectionMode", "[grid]") CHECK(selectedRows.Count() == 1); CHECK(selectedRows[0] == 3); + // Check that overlapping selection blocks are handled correctly. + m_grid->ClearSelection(); + m_grid->SelectBlock(0, 0, 4, 1); + m_grid->SelectBlock(2, 0, 6, 1, true /* add to selection */); + CHECK( m_grid->GetSelectedRows().size() == 7 ); + CHECK(m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows);