wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED Topic is solved

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.
Post Reply
refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh » Wed Feb 27, 2019 7:57 pm

I have a wxDataViewListCtrl. I use a custom wxDataViewCustomRenderer like this:

Code: Select all

ColoredTextCustomRenderer::ColoredTextCustomRenderer() : wxDataViewCustomRenderer("void*", wxDATAVIEW_CELL_INERT, wxALIGN_CENTER)
Please notice that the first parameter to wxDataViewCustomRenderer's constructor is void*.
I also want to use wxEVT_DATAVIEW_ITEM_ACTIVATED like this:

Code: Select all

void MainFrame::Data_view_list_ctrl_unstaged_on_data_view_list_ctrl_item_activated(wxDataViewEvent& event)
{
	void* bla = event.GetValue().GetVoidPtr();
	
	// Some more code goes here...
}

The event fires perfectly. The problem is that bla is always null and I don't understand why.
Can somebody please explain why it is always null?

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

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by doublemax » Wed Feb 27, 2019 8:15 pm

wxEVT_DATAVIEW_ITEM_ACTIVATED is an event that is generated for the whole item (row), not a particular column. So GetValue() doesn't make sense here. But GetItem() should give you the item.
Use the source, Luke!

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh » Thu Feb 28, 2019 7:12 am

doublemax wrote:
Wed Feb 27, 2019 8:15 pm
wxEVT_DATAVIEW_ITEM_ACTIVATED is an event that is generated for the whole item (row), not a particular column. So GetValue() doesn't make sense here.
Oh! I understand now. Thank you.
doublemax wrote:
Wed Feb 27, 2019 8:15 pm
But GetItem() should give you the item.
Eh... Could you please give an example of what should I do with GetItem()? It seems to be returning a wxDataViewItem class and I have no idea how that helps me - what method should I use from the wxDataViewItem class?

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

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by doublemax » Thu Feb 28, 2019 7:21 am

wxDataViewEvent::GetModel() gives you the model. Then you can call wxDataViewModel::GetValue() to get the value from the column you need.

https://docs.wxwidgets.org/trunk/classw ... 724f73074b
https://docs.wxwidgets.org/trunk/classw ... 11c008c67f
Use the source, Luke!

refaelsh
Earned a small fee
Earned a small fee
Posts: 20
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh » Thu Feb 28, 2019 12:38 pm

Thank you. That helped solve my problem.

Post Reply