wxGrid navigation Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

wxGrid navigation

Post by Nunki »

Hi Guys,
Is it possible with a wxGrid set to rowselect, that after a selection of a row by means of a mouseclick, you move the selection one row down with the up and down arrow keys. I added a

Code: Select all

EVT_KEY_DOWN( tcTBbrowse::OnKeyDown )
to the event table.

Code: Select all

nKey = ((wxKeyEvent&)event).GetKeyCode();
 switch(nKey)
  {
   case WXK_F1: // Show info or help
                this->GPopup(ccGevent);
                break;
   case WXK_F5: // Refresh content
                this->RefreshContent();
                break;
   case WXK_UP: // Up arrow pressed
                break;
   case WXK_DOWN: // Down arror pressed
                  hGrid = XRCCTRL(*this, "TBBRWS_GRID", wxGrid);
                  anSel = hGrid->GetSelectedRows();
                  if (anSel.GetCount() > 0)
                    {
                     nRow = anSel.Item(0);
                     hGrid->SelectRow(nRow+1,true);
                     hGrid->Refresh();
                    }
                  break;
  }

 event.Skip();
Key event are caught, the selected row is deselected, but the next row is not highlighted or selected, strangely the next cell is selected but is not highlighted.
I did create the wxGrid with rowselection and no editing cells.

Code: Select all

   hGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
   hGrid->EnableEditing(false);
Am i missing something ?

regards,
Nunki
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid navigation

Post by doublemax »

Don't call event.Skip() if you handle the key event. Otherwise the default behavior for "cursor down" will get executed. Which is to clear the selection and move the grid cursor down.
Use the source, Luke!
Post Reply