CheckListCtrl derived from wxListCtrl 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
snoogie
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Sep 09, 2007 8:22 am
Location: France
Contact:

CheckListCtrl derived from wxListCtrl

Post by snoogie » Tue Sep 25, 2007 8:41 am

Hi, I have a strange problem.
I derived a classe from wxListCtrl in order to inmplement a ListCtrl with checkbox.

So I have a function which add a check item :

Code: Select all

/// Add an item
long wxCheckListCtrl::AddCheckedItem(int _counter, const wxString& _label, bool _checked)
{
	long l_ret;
	wxListItem l_item;
	l_ret = InsertItem(_counter, _label, 1);
    wxCheckListItemAttr* l_data = new wxCheckListItemAttr;
    l_data->SetChecked(_checked);
    l_data->SetTranslatedLabel(_label);
    l_data->SetUntranslatedLabel(_label);
	SetItemData(l_ret, (long)l_data);
	//SetItemPtrData(l_ret, (wxUIntPtr) l_data);
	std::cout << "AddCheckedItem " << _label << " data @ " <<  l_data << "Item : " << l_ret << '\n';
	std::cout << std::hex << GetItemData(l_ret) << '\n';
    SetIcon(l_ret);

	return l_ret;
}
and an execution log is :

AddCheckedItem 0x8226b4c data @ 0x8226c80Item : 7
8226c80

So here we can see that data is well set and can be retrieve using GetItemData

But there is something strange, later, when I click on icon, the callback OnMouseEvent is called :

Code: Select all


void wxCheckListCtrl::OnMouseEvent(wxMouseEvent& event)
{
    int flags = 0;
	long l_subitem;
    long item = HitTest(wxPoint(event.GetX(), event.GetY()), flags, &l_subitem);
	std::cout << "Item : " << item << '\n';
    
    if (event.LeftDown())
    {
        if (flags & wxLIST_HITTEST_ONITEMICON)
        {
			std::cout << "Flag: " << flags << '\n';
			std::cout << "Item: " << std::dec << item << '\n';
            wxCheckListItemAttr* data = (wxCheckListItemAttr*) GetItemData(item);
			std::cout << "Data: " << data << '\n';

			if(data != 0)
			{
				std::cout << "mouse event" << data->GetEnabled() << " " << data->GetChecked() << '\n';
			}
...
But here data = item ... so data->GetChecked() segfault my application.

Maybe someone have an idea ?
Thanks for your help

snoogie
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Sep 09, 2007 8:22 am
Location: France
Contact:

Post by snoogie » Tue Sep 25, 2007 7:31 pm

I finally find a simple solution
On mouse event I toggle from check (id=1 in imagelist) icon to unchecked (id=0) and vice versa.
When retrieving the list, I check if icon is 0 or 1, if 0 I didn't add to result list

I will try to investigate if I have some time this problem

If someone have same problem it can ask me and I will investigate :)

So I close this post

HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

Post by HeReSY » Wed Sep 26, 2007 6:24 am

I don't know why you do this, there is allready a class for it.

http://www.wxwidgets.org/manuals/stable ... ecklistbox

snoogie
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Sep 09, 2007 8:22 am
Location: France
Contact:

Post by snoogie » Wed Sep 26, 2007 7:24 am

I did it, because I need a wxListCtrl (with more than one column) which support checkbox.
You can see it in action here (left panel):
Image
But if you know how do it with a wxCheckListBox :)

Post Reply