Which event is sent when I hit SPACE for a wxGrid with
wxGridCellBoolRenderer?
Volker Bartheld
dr_versaeg at freenet.de
Tue Jan 2 01:14:39 PST 2007
Hi!
Thanks for your reply.
>VB> I tried EVT_KEY_UP with WXK_SPACE, EVT_GRID_CELL_CHANGE and
>VB> EVT_GRID_CELL_LEFT_CLICK - to no avail. Theoretically, hitting SPACE in
>VB> a boolean cell should be equal to EVT_GRID_CELL_LEFT_CLICK - at least on
>VB> wxMSW the cell gets checked/unchecked.
>VB>
>VB> But my EVT_GRID_CELL_LEFT_CLICK handler is never called.
On Tue, 26 Dec 2006 15:33:45 +0100, vadim at wxwindows.org (Vadim Zeitlin)
wrote :
> This is not surprising, it's not a left click so why should it be called?
>However EVT_GRID_CELL_CHANGE should be called when you accept the changes
>in the cell.
Actually, I wanted the value of a wxGridCellBoolRenderer cell toggle its
value by a single mouseclick on the checkbox - without displaying the
native editor first. I implemented this like below, handling
EVT_GRID_CELL_LEFT_CLICK of my derived class wxControlGrid that has a
member function that returns the nature of a cell's renderer [is there a
function in wxGrid that already does what I want?]:
BEGIN_EVENT_TABLE(wxControlGrid,wxGrid)
EVT_GRID_CELL_LEFT_CLICK(wxControlGrid::OnCellLClick)
END_EVENT_TABLE()
void wxControlGrid::OnCellLClick(wxGridEvent& event)
{
if(IsReadOnly(event.GetRow(), event.GetCol())) // if cell is readonly, no need in showing the edit control
{
event.Skip();
return;
} // if(IsReadOnly(event.GetRow(), event.GetCol()))
switch(GetCellRendererType(event.GetRow(), event.GetCol()))
{
case eRENDERER_BOOL:
{
// for bool renderers (checkboxes) toggling should occur for the first click
unsigned long ul;
if(GetCellValue(event.GetRow(), event.GetCol()).ToULong(&ul, 2)) // was there a valid bool value in there (ULONG(0) or ULONG(1))?
SetCellValue(event.GetRow(), event.GetCol(), int2string((int)!ul)); // then invert it
SetCurrentCell(event.GetRow(), event.GetCol()); // set focus to this cell
SelectRow(event.GetRow()); // and select the row
break;
} // case eRENDERER_BOOL:
} // switch(GetCellRendererType(event.GetRow(), event.GetCol()))
}
Then, I found out that hitting the SPACE bar results in the same action
as clicking the cell. To have a common look&feel, this should be handled
like above. EVT_GRID_CELL_CHANGE is, if I understand the way it works
correctly, too late for a mission like this.
Cheers,
Volker
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list