Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / ListBox doubleclick event

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. ListBox doubleclick event
#2986
Posted by: 2003-11-26 20:08:30
-I have a listbox with strings.

CodecsBox = new wxListBox(this, CodecsLB, wxPoint(20,30), wxSize(240,380), 0, NULL, wxLB_MULTIPLE | wxLB_NEEDED_SB | wxLB_SORT);

-I have a DCLICK event for this listbox:

EVT_LISTBOX_DCLICK(CodecsLB, OnCodecsDBC)

-I have the event handler for this event:

void cAnalysisDialog::OnCodecsDBC(wxCommandEvent &event)
{
  wxMessageBox(event.GetString());
}



If i run the program and double click any of the strings, i get an empty messagebox.
Why doesn't   event.Getstring()   work in my program?  it looks really the same in the sample that came with wxWindows.

Anyone please help me?

thanx.
Message2. Re: ListBox doubleclick event
#2991
Posted by: upCASE 2003-11-27 00:49:50
Hi!
Just tried it and for me it works, but I got an error during compilation. Be sure to use
EVT_LISTBOX_DCLICK(CodecsLB, cAnalysisDialog::OnCodecsDBC)
instead of
EVT_LISTBOX_DCLICK(CodecsLB, OnCodecsDBC)

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: ListBox doubleclick event
#2997
Posted by: 2003-11-27 18:14:06
this is my event table:

BEGIN_EVENT_TABLE(cAnalysisDialog, wxDialog)
   EVT_BUTTON(CloseAnalysisBTN, OnCloseButton)
   EVT_BUTTON(CriticalAnalysisBTN, OnCriticalButton)
   EVT_BUTTON(CreateAnalysisBTN, OnCreateButton)
   EVT_LISTBOX_DCLICK(CodecsLB, OnCodecsDBC)
   EVT_LISTBOX_DCLICK(ItemsLB, OnItemsDBC)
   EVT_LISTBOX_DCLICK(ListenersLB, OnListenersDBC)
END_EVENT_TABLE()

doesnt work at all :(

could you send me the sample program you made to test it, maybe that will show me something i forgot?
Message4. Re: ListBox doubleclick event
#2998
Posted by: 2003-11-27 18:23:13
By the way, if i use   event.GetSelection , it always gives me '0'.
Message5. Re: ListBox doubleclick event
#2999
Posted by: 2003-11-27 18:35:13
And when i run, i DO get a messagebox when i double click anything in the listbox.

So the event handler is called, thats no problem. The event parameter just doesnt seem to have the proper values. event.getmessage returns an empty string. event.getselection returns 0.

The listbox seems to work alright though. after i added the items to it, i can use it as i am supposed to:    CodecsBox->GetSelections does give me a the proper array with selections.
Message6. Re: ListBox doubleclick event
#3000
Posted by: upCASE 2003-11-27 19:42:42
Hi!
Well, the major difference between my sample app and yours is that I used a wxFrame instead of a wxDialog. I'm currently at work so I can't test things out right now, but I do have some thoughts I would need to confirm.

Normally, as I said, you would use MyDialog::EventHandler instead of EventHandler when setting up the event tables. And you use the DECLARE_EVENT_TABLE() macro in your class. Not doing so when programming a wxFrame will result in compiler errors and it won't work. Now, I'm not sure how a dialog is implemented in wxWindows (I'll check that later), butt I'm pretty sure that (at least) under Windows a dialog allways has an event loop of it's own, seperated from tha main event loop used by your main app. Now I do suspect that since there is an event loop, your code really compiles, but doesn't do what it should. Maybe it's because the events are generated and posted, but not triggered the right way....

Therefor GetSelections() used on the control works, but not when using the event. Just to be sure:
1. Have you used DECLARE_EVENT_TABLE()?
2. Did you try using
    EVT_BUTTON(CloseAnalysisBTN, cAnalysisDialog::OnCloseButton)
   etc. in the event table?

Still, I have to say that this is kinda strange... I'll check that later at home.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message7. Re: ListBox doubleclick event
#3004
Posted by: 2003-11-27 21:07:16
yes i have declare event table.

The events DO happen, else the messagebox with empty string would not even appear.
I have multiple event tables all similar like these and all other events (buttons, checkboxes, radiobuttons), including the button events in this table, work properly.

The difference is non of the other event handlers actually use the event parameter that is given them.  This is the only one.

I will now post all of the relevant code:


cAnalysisDialog::cAnalysisDialog(wxSortedArrayString &Codecs, wxSortedArrayString &Items, wxSortedArrayString &Listeners, wxString &DefFile)
Message8. Re: ListBox doubleclick event
#3005
Posted by: 2003-11-27 21:25:40
yes i have declare event table.

The events DO happen, else the messagebox with empty string would not even appear.
I have multiple event tables all similar like these and all other events (buttons, checkboxes, radiobuttons), including the button events in this table, work properly.

The difference is non of the other event handlers actually use the event parameter that is given them.  This is the only one.

I will now attach the relevant code. (not the whole project, just copy paste some sections, whole project would be quite a lot)
Message9. Re: ListBox doubleclick event
#3006
Posted by: 2003-11-27 21:28:36
oops sorry, first one wasnt supposed to be posted
Message10. Re: ListBox doubleclick event
#3019
Posted by: upCASE 2003-11-29 02:41:30
Hi!

Leaving the "relevant code" aside (the ctor was of no real use and the attachment never made it :) ) I can only say that I tried it and for me it gave a compiler error. "ISO C++ forbids taking the address of a bound member function to form a pointer to member function.  Say `&cDialog::OnList'" when using EVT_LISTBOX_DCLICK(ID_LIST, OnList) like you did. I never got this to compile.

Anyway, since I can't look into your sources and check it, I'll post my test dialog app. It compiles and works just fine for me (gcc 3.2.3, wxWindows 2.4.2, Dev-C++ 4.9.8.5)

main.cpp

#include <wx/wx.h>
#include <wx/image.h>
#include "cDialog.h"



class MyApp: public wxApp {
public:
    bool OnInit();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    wxInitAllImageHandlers();
    cDialog* dialog_1 = new cDialog(0, -1, "");
    SetTopWindow(dialog_1);
    dialog_1->Show();
    return true;
}

cDialog.h

#include <wx/wx.h>
#include <wx/image.h>

#ifndef CDIALOG_H
#define CDIALOG_H

class cDialog: public wxDialog {
public:
    enum {
        ID_LIST = 1000
    };


    cDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE);

private:
    void set_properties();
    void do_layout();

    void OnQuit(wxCloseEvent &e);
    void OnList(wxCommandEvent &e);
    DECLARE_EVENT_TABLE()
protected:
    wxListBox* listBox;

};

#endif // CDIALOG_H

cDialog.cpp

#include "cDialog.h"
BEGIN_EVENT_TABLE(cDialog, wxDialog)
    EVT_CLOSE(cDialog::OnQuit)
    EVT_LISTBOX_DCLICK(ID_LIST, cDialog::OnList)
END_EVENT_TABLE()

cDialog::cDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE)
{

    const wxString listBox_choices[] = {
        wxT("choice 1"),
        wxT("choice 2"),
        wxT("choice 3")
    };
    listBox = new wxListBox(this, ID_LIST, wxDefaultPosition, wxDefaultSize, 3, listBox_choices, wxLB_SORT);

    set_properties();
    do_layout();

}
void cDialog::OnList(wxCommandEvent &e)
{
    wxMessageBox(e.GetString());
}
void cDialog::OnQuit(wxCloseEvent &e)
{
    Destroy();
}

void cDialog::set_properties()
{
    SetTitle(wxT("dialog_1"));
    listBox->SetSelection(0);

}


void cDialog::do_layout()
{

    wxBoxSizer* sizer_2 = new wxBoxSizer(wxHORIZONTAL);
    sizer_2->Add(listBox, 1, wxALL|wxEXPAND, 0);
    SetAutoLayout(true);
    SetSizer(sizer_2);
    sizer_2->Fit(this);
    sizer_2->SetSizeHints(this);
    Layout();

}
upcase

upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message11. Re: ListBox doubleclick event
#3039
Posted by: 2003-12-01 17:13:23
heh, i copy pasted the 3 files, made a project with them, compiled, program runs, and i have the same problem i had in my own project.

An empty messagebox.

:(

I have version 2.2.9 though, guess i'll need to try a newer version?
Message12. Re: ListBox doubleclick event
#3040
Posted by: upCASE 2003-12-01 20:03:22
Hi!
Well, this is strange...
I'm pretty sure that version 2.4.2 offers a lot bugfixes, but I'm not sure if wxListBox caused such a problem in version 2.2.9. Maybe give it a try.
This is weird. If updating to 2.4.2 doesn't help I suggest that you mail your problem to the wxWindows list.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message13. Re: ListBox doubleclick event
#3048
Posted by: 2003-12-03 18:21:58
New problems when keep showing everytime i solve something.

Seems like wxWindows is not meant to be upgradable to a new version with the same programm. I give up on this and will work my way around it by using the EVT_LISTBOX event (single click) to set some variable i will read out in the double click event handler to see what was the last selected item (when you double click, single click event is also activated)
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2023-2-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0