Improving the functionality of comboboxes in wxGrid
The grid in wxWidgets
allows you to insert a combobox in a cell,
which is a
feature that very few other toolkits offer.
However, the default behaviour is somewhat lacking.
First of all, there is no visual indication of which cell has a combox
until the cell has focus.
Then, when you click on a cell to edit it you have to click three
times:
once to give the cell focus, once to activate the editor and a third to
actaully open the combobox. Not very user friendly if you have a few
dozen items to edit.
I wrote some classes to rectify these problems:
wxGridCellChoiceRenderer
|
displays the combobox buttons when not active. |
ezGrid
|
activates cells in the grid with just one click |
wxFastComboEditor
|
Opens the comboxbox immediately if you clicked on the button
|
To use this code include the files in this zip file in your project:
Then insert the combobox into the cell
like this:
#include "EzGrid.h"
#include
"wxgridcellcombobox.h"
....
EzGrid *grid;
grid = new EzGrid( this, -1,
wxPoint( 0, 0 ), wxSize( 400, 300 ) );
grid->CreateGrid( 4, 4
);
grid->SetCellRenderer(1, 1, new wxGridCellChoiceRenderer);
wxString
strChoices[3] = {"one", "two", "three"};;
grid->SetCellEditor(1, 1,
new wxFastComboEditor(3, strChoices,
TRUE));
Notes:
ExGrid will put all cells into edit mode with just one click, not just
the comboboxes. Normally this is desirable because you can edit the
cells
quicker.
The code works under both Windows and Linux (wxGTK), except for the
code that opens the combobox automatically. I'm not very experienced in
GTK and I haven't yet figured out how to send a left mouse click
message
to a control.