我在可编辑模式下创建了 wxGrid。我注册了以下事件处理程序。
class ReadWriteGrid : public wxGrid
{
public:
ReadWriteGrid(wxWindow *parent, wxWindowID ID,
const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize,
long style=262144, const wxString &name=wxGridNameStr)
: wxGrid(parent, ID, pos, size, style, name)
{
SetEditable();
}
};
EVT_GRID_CELL_CHANGE(IndexTableFrame::OnEditField)
现在,当用户更改单元格值时,我的函数被调用但在它完成之后。单元格值变回其旧值。
void IndexTableFrame::OnEditField(wxGridEvent& event)
{
int RowNumber;
int ColNumber;
wxString type;
wxGridCellEditor *m_Editor;
wxString NewValue;
RowNumber = event.GetRow();
ColNumber = event.GetCol();
m_Editor = m_grid->GetDefaultEditorForCell(RowNumber,ColNumber);
NewValue = m_Editor->GetValue();
m_Editor->Destroy();
m_grid->SetCellValue(NewValue,RowNumber,ColNumber);
event.skip();
}
这是我第一次使用 WxWidget。我不确定如何避免单元格变回其旧值。