Checked List Control for wxWidgets

For any people who are looking for a checked list component for wxWidgets– you might find this article revealing.

I’ve been using wxWidgets for a couple of months and I have to say it’s awesome. But, when I looked in the docs for a checked list control, I was not very excited to find that it does not exist in the 2.8.10 release. After doing some googling, I found the wiki page that gives some hints on using a subclass of wxListCtrl as a checked list control.

The wiki will tell you get the .cpp and the .h from the webupdate component page. The specific files I used can be downloaded from these locations:

  1. download the latest wxcheckedlistctrl.php revision from this page: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/src/checkedlistctrl.cpp?view=log
  2. download the latest revision for wxcheckedlistctrl.h from: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checkedlistctrl.h?view=log
  3. download the bitmap images from: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checked.xpm?view=log
  4. http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checked_dis.xpm?view=log
  5. http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/unchecked.xpm?view=log
  6. http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/unchecked_dis.xpm?view=log

then edit the wxcheckedlistctrl.h to point to the right xpm images for the control. Include the .h and .cpp files in your project. I had to write a few additional hacks to the .h file but I got it to work just fine. There are a couple of methods not implemented in the implementation file. Today I spent quite a while trying to sort the items in the list using the SortItems method, then found out that It wasn’t implemented. Below, is the SortItems method for wxCheckedListCtrl as written by me, each row should have a unique value set by SetItemData(..)


bool SortItems(wxListCtrlCompare c, long le)
{
long ic = GetItemCount();
long *b_CE = new long[ic*2];    // first half is checked.. 2nd is enabled

long chc = 0, enc = 0;
for(long l=0;l<ic;++l)
{
if(IsChecked(l))
b_CE[chc++] = GetItemData(l);
if(IsEnabled(l))
b_CE[ic+(enc++)] = GetItemData(l);
}

if(!wxListCtrl::SortItems(c, le))
{
delete [] b_CE;
return false;
}

CheckAll(false);
EnableAll(false);
for(long l=0;l<ic;++l)
{
for(long l2=0;l2<chc;l2++)
if(b_CE[l2] == GetItemData(l))
Check(l, true);
for(long l2=0;l2<enc;l2++)
if(b_CE[ic+l2] == GetItemData(l))
Enable(l, true);
}

delete [] b_CE;
//             wxASSERT_MSG(0, wxT("Not implemented yet ! sorry... ")); return FALSE;
return true;
}

Tags:

Leave a Reply

Post Categories

Ready Made Templates

Template 30420Template 30409Template 30026Template 30173Template 30165Template 30136Template 30122Template 30119Template 30074

About ProjectiveMotion

We develop cost effective websites for small to mid size businesses. Our passion is customer service and a job well done. We make use of all tools available in order to provide the product to fit your needs.

Do you have a business? Do you have a website? Don't know how to get started? We answer all inquiries within 12 hours. Our products have 30 day free client support.