wxListCtrl w/ checkbox

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
rz
Knows some wx things
Knows some wx things
Posts: 35
Joined: Thu Jul 28, 2005 2:01 pm
Location: MidWest -- USA

wxListCtrl w/ checkbox

Post by rz »

Hi all,

I know (ok, I strongly suspect) there is a way to put a checkbox control as an item in a (report style) list control, and have seen a items indicating that it worked in wxPython, but I need a C++ List Control with a checkbox.

If someone has solved this problem, would you be so kind as to share? Or if someone has a few hints, please let me know.

Thanks!
-rz.
-rz.
----------------------
"Like so many Americans, she was trying to construct a life that made sense from things she found in gift shops." -- Kurt Vonnegut.
-----------------------
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Did you have a look at wxCheckListBox?
rz
Knows some wx things
Knows some wx things
Posts: 35
Joined: Thu Jul 28, 2005 2:01 pm
Location: MidWest -- USA

Post by rz »

It is *almost* exactly what I need, but I need multiple columns (ala report style list control). Can I add columns to the wxCheckListBox?
-rz.
----------------------
"Like so many Americans, she was trying to construct a life that made sense from things she found in gift shops." -- Kurt Vonnegut.
-----------------------
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

I think your best guess is use a wxGrid or wxSheet for the columns and set one of the cells to a boolean cell, which represents the checkbox.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor »

You can do it by derivate the wxListCtrl and handly add checkbox placement.
You just have to handle size and scroll event and use GetItemRect/GetItemPosition functions to retrieve item position and move checkbox consequently.
Tip : you can store checkbox address in the ListItem extra data.
What is little and green, witch go up and down ??
Yoda playing with the force.
geralds
I live to help wx-kind
I live to help wx-kind
Posts: 186
Joined: Tue Nov 01, 2005 9:22 am
Contact:

Post by geralds »

rz is making an important point here. wxListCtrl lacks a widely used property of the Win32 ListView control in report mode. (Win32 even offers convenience functions for checking and unchecking items.)

I wrote my own wrapper for a Win32 ListView a while back (before I discovered wxWidgets!) and it's very easy to implement checkbox list views on Windows:

Code: Select all

/*
  // ctrlHwnd is of type HWND
  SendMessage(
    ctrlHwnd,
    LVM_SETEXTENDEDLISTVIEWSTYLE,
    0,
    LVS_EX_CHECKBOXES);
*/

void ListViewControl::setCheckState(bool b, int item)
{
  ListView_SetCheckState(ctrlHwnd, item, (b) ? TRUE : FALSE);
}
My problem is that I have no experience creating as opposed to using components in wxWidgets.

In short, this is something that would be a valuable addition to the standard wxListCtrl and well worth folding back into the main distribution.
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

It would be a valuable addition to a new control.
wxListCtrl API is too windows centric to do anything on top of it on other platforms, while staying sane.
Now for that new control there would be help most appreciated.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
geralds
I live to help wx-kind
I live to help wx-kind
Posts: 186
Joined: Tue Nov 01, 2005 9:22 am
Contact:

Post by geralds »

Fair point. If I work out how it's done, I will certainly post it here.
lrm
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Nov 20, 2004 9:12 pm
Location: San Jos

Post by lrm »

rz
Knows some wx things
Knows some wx things
Posts: 35
Joined: Thu Jul 28, 2005 2:01 pm
Location: MidWest -- USA

Post by rz »

Thanks for the tip, but I didn't find anything applicable --
did I miss it? (if so, where?).

Thanks!

-rz.
-rz.
----------------------
"Like so many Americans, she was trying to construct a life that made sense from things she found in gift shops." -- Kurt Vonnegut.
-----------------------
lrm
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Nov 20, 2004 9:12 pm
Location: San Jos

Post by lrm »

Download file webupdate-1.0.tar.gz (from http://wxcode.sourceforge.net/components/webupdate/) there is a class named wxCheckedListCtrl (files checkedlistctrl.h/cpp)

:wink:
qgranfor
Experienced Solver
Experienced Solver
Posts: 89
Joined: Sun Aug 29, 2004 7:32 pm
Location: ND...USA
Contact:

Post by qgranfor »

Post Reply