2

I've created a wxGrid, populated it with data, and have created a column that contains checkboxes, and made them editable. All good so far.

co_Grid->SetReadOnly(at_RowCount, 24, false);    
co_Grid->SetCellRenderer(at_RowCount, 24,  new wxGridCellBoolRenderer); 
co_Grid->SetCellEditor(at_RowCount, 24, new wxGridCellBoolEditor);

What I want to be able to do now is to add an event handler for the checkbox toggle event.

I've tried using the OnCellValueChanged event for the grid, but that only fires after the user leaves the cell, because before then the editor is still open (and the cell hasn't actually changed yet)

I'm pretty sure that I need to create an event handler for the wxGridCellBoolEditor but that's where I'm struggling.

I tried connecting an event in the OnEditorShown event, but that didn't go well (unhandled exception when I click on the cell to open the editor):

void cTeamGrid::OnEditorShown( wxGridEvent& ev )
{
    int row = ev.GetRow(),
        col = ev.GetCol();

    co_Grid->GetCellEditor(row, col)->GetControl()->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, 
        wxCommandEventHandler(cTeamGrid::OnGridCheckChange), NULL, this);
}

What am I doing wrong?

Dave
  • 1,696
  • 4
  • 23
  • 47

1 Answers1

0

I had a similar problem myself. I bypassed it by setting the checkbox column to read-only and having the wxGrid control manually handle the click event to toggle the checkbox state (you also have to manage the double-click). This method is not the most orthodox, also because now each click on the cell, and not on the checkbox, will change the state. In my opinion, however, this can also be a desirable behaviour. In addition, this enables you to let the user change the checkbox with the keyboard (by capturing the KeyPress events).

Alberto M
  • 1,057
  • 8
  • 24