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
Knows some wx things
Knows some wx things
Posts: 29
Joined: Tue Feb 05, 2019 7:25 pm

wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh »

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: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by doublemax »

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
Knows some wx things
Knows some wx things
Posts: 29
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh »

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: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by doublemax »

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
Knows some wx things
Knows some wx things
Posts: 29
Joined: Tue Feb 05, 2019 7:25 pm

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Post by refaelsh »

Thank you. That helped solve my problem.
Post Reply