From: Christian Hackl on 30 Nov 2009 05:30 Hi! As I take it, the recommended workaround for the fact that list selection events cannot be vetoed is to manually reset the selection to its previous state. However, when I try to do so, the event handler is called twice in the process. Here's a dumbed-down yet complete piece of code illustrating the problem: #include <wx/wx.h> #include <wx/listctrl.h> class MainWindow : public wxFrame { public: MainWindow() : wxFrame(0, wxID_ANY, "Double Event Test"), list_(new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST )) { Connect(list_->GetId(), wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(MainWindow::onSelect)); list_->InsertItem(0, "0"); list_->InsertItem(1, "1"); list_->InsertItem(2, "2"); wxSizer *sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(list_, 1, wxALL, 5); SetSizer(sizer); } void onSelect(wxListEvent &event) { static bool ignore = false; if (ignore) return; if (wxMessageBox("Really?", "Really?", wxYES_NO) == wxNO) { ignore = true; list_->Select(0, true); ignore = false; list_->Select(1, false); list_->Select(2, false); } } private: wxListView *list_; }; class Application : public wxApp { public: virtual bool OnInit() { MainWindow *main_window = new MainWindow; main_window->Show(true); return true; } }; IMPLEMENT_APP(Application) When I select a list item and click "No" in the dialog box, the dialog immediately pops up again. (Actually, the handler is called three times, so if I did not have that "ignore" variable in the code, the dialog would pop up three times as well.) Somehow, the event seems to occur again immediately *after* the event handler finishes, and I can't for the heck of it figure out why. To add insult to injury, everything happens as it should when I step through the very same build in a debugger. I'm using VC++ 2008 (Version 9.0.30729.1 SP) and wxWidgets 2.8.9 on Windows XP SP2. Is this a bug? Am I trying to do something horribly wrong? What can I do? Any hints appreciated. Thanks, Christian -- Christian Hackl hacki(a)sbox.tugraz.at Milano 2008/2009 -- L'Italia chiam�, s�!
|
Pages: 1 Prev: why wxXmlDocument.Load() return False ? Next: scrolledwindow |