by James Bott » Thu Jun 29, 2006 5:19 pm
Greg,
You have to use a trick to make it appear like it is a control. Below is a copy of my notes on this.
James
----------------------------
Here is how to do a checkbox in a listbox:
You need to use two bimaps for the checkbox, one checked and one unchecked. Load the bitmaps:
hChecked:=loadbitmap( getresources(),"checked")
hUnchecked:= loadbitmap( getrources(),"unchecked")
Define the bitmaps conditionally in the listbox definition:
@0,0 listbox oLbx fields date, description, ;
if(empty(::oTask:completed),hChecked,hUnchecked)
Then you have to define an action when the column is clicked on:
oLbx:blClicked := {| nRow, nCol| ( if(oLbx:nAtCol(nCol)=3,;
toggleCheck(),),oLbx:drawSelect()) }
The above line checks for column 3. If that is the column, then the function toggleCheck() is called. ToggleCheck() toggles the variable and saves the record. Finally, you redraw the line using oLbx:drawSelect().
[Note: You may need to pass nRow and check to make sure it is greater than 15 to avoid triggering the checkbox when the user clicks on the header. See file:///c:\apps\todo\task.prg, method click() for an example.]