wxDataViewListCtrl on click item action not executing.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 8:12 am

I have a wxDataViewListCtrl which I bind for when a item is clicked as

Code: Select all

    Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this, BCID_SampleListView);
And the related function is,

Code: Select all

void Browser::OnClickSampleView(wxDataViewEvent& event)
{
    std::cout << "\n Click Sample View \n";

    std::string selection = SampleListView->GetTextValue(SampleListView->GetSelectedRow(), 1).ToStdString();

    std::cout << selection << "\n";
}
But nothing happens when I click on a item, nothing prints to console no error. What am I doing wrong?

User avatar
[email protected]
Experienced Solver
Experienced Solver
Posts: 68
Joined: Wed Jul 29, 2020 6:06 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by [email protected] » Tue Jan 12, 2021 10:38 am

Try without the ID BCID_SampleListView.
What's the context of the Bind() call? In order for this to work, the wxDVC must be descendant (child, grandchild, etc) of "this"

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 11:56 am

[email protected] wrote:
Tue Jan 12, 2021 10:38 am
Try without the ID BCID_SampleListView.
What's the context of the Bind() call? In order for this to work, the wxDVC must be descendant (child, grandchild, etc) of "this"
Sorry I don't follow, what do you mean by wxDVC should be descendant (child, grandchild, etc) of "this" ?

The Browser class is inheriting from wxPanel, so "this" pointer is basically wxPanel, and there are 2 wxSplitterWindow on this panel, 1 splitter splits horizontally into a panel and another splitter which splits vertically into 2 other panels. This wxDataViewListCtrl is on the bottom right panel.

User avatar
[email protected]
Experienced Solver
Experienced Solver
Posts: 68
Joined: Wed Jul 29, 2020 6:06 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by [email protected] » Tue Jan 12, 2021 12:43 pm

apoorv569 wrote:
Tue Jan 12, 2021 11:56 am
The Browser class is inheriting from wxPanel, so "this" pointer is basically wxPanel, and there are 2 wxSplitterWindow on this panel, 1 splitter splits horizontally into a panel and another splitter which splits vertically into 2 other panels. This wxDataViewListCtrl is on the bottom right panel.
Then it's ok. wxCommandEvents propagate upwards in the window hiearchy, so the wxDVC must be a descendant of browser (in the window hiearchy), otherwise the event can't reach the Browser class.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 1:04 pm

[email protected] wrote:
Tue Jan 12, 2021 12:43 pm
apoorv569 wrote:
Tue Jan 12, 2021 11:56 am
The Browser class is inheriting from wxPanel, so "this" pointer is basically wxPanel, and there are 2 wxSplitterWindow on this panel, 1 splitter splits horizontally into a panel and another splitter which splits vertically into 2 other panels. This wxDataViewListCtrl is on the bottom right panel.
Then it's ok. wxCommandEvents propagate upwards in the window hiearchy, so the wxDVC must be a descendant of browser (in the window hiearchy), otherwise the event can't reach the Browser class.
I see, any idea why its not working for me then, any way to debug?

User avatar
[email protected]
Experienced Solver
Experienced Solver
Posts: 68
Joined: Wed Jul 29, 2020 6:06 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by [email protected] » Tue Jan 12, 2021 1:17 pm

The only other reason i can think of is a wrong ID.
Try without the ID BCID_SampleListView [in the Bind call].
Did you try that?

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 1:35 pm

[email protected] wrote:
Tue Jan 12, 2021 1:17 pm
The only other reason i can think of is a wrong ID.
Try without the ID BCID_SampleListView [in the Bind call].
Did you try that?
I did try it without the ID. No luck.

The ID used in bind and the creation of wxDataViewListCtrl is same,

Code: Select all

    SampleListView = new wxDataViewListCtrl(BottomRightPanel, BCID_SampleListView, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES);
Weird, no idea why its not working.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4870
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewListCtrl on click item action not executing.

Post by ONEEYEMAN » Tue Jan 12, 2021 3:37 pm

Hi,
You handling the event in the "Browser" class, but you create a control using "BottomRightPanel".

Are you sure it the same class?

Thank you.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 6:06 pm

ONEEYEMAN wrote:
Tue Jan 12, 2021 3:37 pm
Hi,
You handling the event in the "Browser" class, but you create a control using "BottomRightPanel".

Are you sure it the same class?

Thank you.
Yes, Browser class is inheriting from wxPanel, everything else is drawn on this panel, including the other 2 panels. The reason I'm drawing panels on top of a panel is because, on the top most panel i.e "this", has some buttons on it self too in the bottom end. Everything I posted here is in one single file.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2856
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by PB » Tue Jan 12, 2021 6:15 pm

This is odd, I would try (assuming this is a Browser instance)

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
If this works, it means that SampleListView is not in a child of Browser (no matter how many levels deep it may be).

If even this does not work, you will have to doublecheck everything again and provide more relevant code.

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 9:43 pm

PB wrote:
Tue Jan 12, 2021 6:15 pm
This is odd, I would try (assuming this is a Browser instance)

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
If this works, it means that SampleListView is not in a child of Browser (no matter how many levels deep it may be).

If even this does not work, you will have to doublecheck everything again and provide more relevant code.
Tried this, no luck, if I type anything else than "this" it says it must Browser*. Its strange.

These are all my bindings in this file

Code: Select all

    Bind(wxEVT_DIRCTRL_FILEACTIVATED, &Browser::OnClickDirCtrl, this, BCID_DirCtrl);
    Bind(wxEVT_BUTTON, &Browser::OnClickPlay, this, BCID_Play);
    Bind(wxEVT_TOGGLEBUTTON, &Browser::OnClickLoop, this, BCID_Loop);
    Bind(wxEVT_BUTTON, &Browser::OnClickSettings, this, BCID_Settings);
    Bind(wxEVT_CHECKBOX, &Browser::OnCheckAutoplay, this, BCID_Autoplay);
    Bind(wxEVT_SCROLL_THUMBTRACK, &Browser::OnSlideVolume, this, BCID_Volume);
    Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this, BCID_SampleListView);
    Bind(wxEVT_TEXT_ENTER, &Browser::OnDoSearch, this, BCID_Search);
    Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &Browser::OnDoSearch, this, BCID_Search)
    Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &Browser::OnCancelSearch, this, BCID_Search);
All of them work, except this wxDataViewListCtrl one.
Last edited by apoorv569 on Tue Jan 12, 2021 9:52 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15688
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl on click item action not executing.

Post by doublemax » Tue Jan 12, 2021 9:48 pm

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
Please show more code in context. There must be some detail you're not telling us :)
Use the source, Luke!

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 9:57 pm

doublemax wrote:
Tue Jan 12, 2021 9:48 pm

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
Please show more code in context. There must be some detail you're not telling us :)
Here is the link to the file, you can navigate to full project as well. I just pushed the latest commit.

https://gitlab.com/apoorv569/cpp-projec ... r.cpp#L163

You can run the build.sh script to build it.

User avatar
doublemax
Moderator
Moderator
Posts: 15688
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl on click item action not executing.

Post by doublemax » Tue Jan 12, 2021 10:47 pm

I can't build this under Windows, so i can't test this. (BTW: If you want your code to work properly under Windows at some time in the future, you'll need to get rid of at least some of the std::string, or you will get issues with wide characters)

But i unfortunately i can't spot the mistake either. For a test can you try to Bind wxEVT_DATAVIEW_ITEM_ACTIVATED (which should trigger on double-clicking an entry) ?

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
Also, PB's suggestion should at least have compiled. What was the exact error message you got?

BTW: It should be obvious, but just to be sure: The DVC must contain some items, these events won't fire when clicking on empty space :)
Use the source, Luke!

apoorv569
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl on click item action not executing.

Post by apoorv569 » Tue Jan 12, 2021 11:35 pm

I can't build this under Windows, so i can't test this. (BTW: If you want your code to work properly under Windows at some time in the future, you'll need to get rid of at least some of the std::string, or you will get issues with wide characters)
Thank you for the suggestion, I will keep it in mind.
But i unfortunately i can't spot the mistake either. For a test can you try to Bind wxEVT_DATAVIEW_ITEM_ACTIVATED (which should trigger on double-clicking an entry) ?
I tried binding wxEVT_DATAVIEW_ITEM_ACTIVATED, still no luck. Could it be a bug? Maybe in my installation?

Code: Select all

SampleListView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &Browser::OnClickSampleView, this);
Also, PB's suggestion should at least have compiled. What was the exact error message you got?
Yes it did compile, but it didn't work, and I got no error either.
BTW: It should be obvious, but just to be sure: The DVC must contain some items, these events won't fire when clicking on empty space :)
Yes, I'm adding data to it first, then clicking on rows.

The wxSearchCtrl is also on the same panel as wxDataViewListCtrl, search ctrl works fine. Its just the dataview that's not working, I even tried wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, as I have a toggle column in the dataview it does not work either.

Post Reply