Page 1 of 1

wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Posted: Wed Feb 27, 2019 7:57 pm
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?

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Posted: Wed Feb 27, 2019 8:15 pm
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.

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Posted: Thu Feb 28, 2019 7:12 am
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?

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Posted: Thu Feb 28, 2019 7:21 am
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

Re: wxDataViewListCtrl and wxEVT_DATAVIEW_ITEM_ACTIVATED

Posted: Thu Feb 28, 2019 12:38 pm
by refaelsh
Thank you. That helped solve my problem.