LB Booster
Programming >> Liberty BASIC language >> List view check box selection
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1424017035

List view check box selection
Post by Phineas Freak on Feb 15th, 2015, 3:17pm

As i read from MSDN, the status (set or unset) of a list view check box can be changed by sending the LVM_SETITEMSTATE message:

Code:
struct LVITEM,               _
    	mask       as ulong, _
    	iItem      as long,  _
    	iSubItem   as long,  _
    	state      as ulong, _
    	stateMask  as ulong, _
    	pszText$   as ptr,   _
    	cchTextMax as long,  _
    	iImage     as long,  _
    	lParam     as long,  _
    	iIndent    as long

function LVM.SETITEMSTATE(hWnd, nRow, nState)

	LVITEM.mask.struct	= _LVIF_STATE
	LVITEM.state.struct     = nState
	LVITEM.stateMask.struct = _LVIS_STATEIMAGEMASK or _LVIS_SELECTED

     	calldll #user32, "SendMessageA",     _
		hWnd              as ulong,  _
        	_LVM_SETITEMSTATE as long,   _
        	nRow              as long,   _
        	LVITEM  	  as struct, _
        	LVM.SETITEMSTATE  as long

end function
 


Where nRow is the selected row index value and nState the state of the check box.

The problem with the above code is that it highlights the selected index but it doesn't change it's check box status. I have been looking everywhere for a solution but without much success.

I also tried different things like:

* Setting '4096' for the unset state and '8192' for the set (as reported by the LVM_GETITEMSTATE message) instead of '1' and '2' reported by the LVS_EX_CHECKBOXES style.
* Replacing the "mask" and "stateMask" values.
Re: List view check box selection
Post by Richard Russell on Feb 15th, 2015, 3:41pm

on Feb 15th, 2015, 3:17pm, PreciseTiming wrote:
I also tried different things like: Setting '4096' for the unset state and '8192' for the set (as reported by the LVM_GETITEMSTATE message) instead of '1' and '2' reported by the LVS_EX_CHECKBOXES style.

4096 and 8192 should be correct (the '1' and '2' referred to are values of the State Image Index, which is held in bits 12-15 of the state). If that isn't working try omitting LVIS_SELECTED from the state mask: perhaps it doesn't like changing both the image index (checkbox state) and the selected state at the same time.

If that still doesn't work you could try the other possible values of the image index (there are 16 in all) but my understanding is that 4096 and 8192 are the right values to use.

If Comctrl version 6.0 is required for this functionality (that isn't clear to me from MSDN) you will need to change the manifest because LBB only calls for Comctrl 4.7.

Richard.

Re: List view check box selection
Post by Phineas Freak on Feb 15th, 2015, 5:57pm

Finally, i made it to work. This is good and bad at the same time (and makes me look stupid)...

The good news are that the '4096' and '8192' values work. Also, the LVIS_SELECTED mask doesn't seem to matter.

The bad news are that it doesn't work with my original code. I wrote a quick and dirty program just to test the check box selection and it works perfectly. So, back to the drawing board... :P

Sorry for wasting your time Richard...i should triple check my code next time.

EDIT: Yep, i had a BIG mistake. For some reason i moved this line:

Code:
null = SendMessageLong(hWndListView, _LVM_SETEXTENDEDLISTVIEWSTYLE, _LVS_EX_CHECKBOXES or _LVS_EX_FULLROWSELECT, _LVS_EX_CHECKBOXES or _LVS_EX_FULLROWSELECT) 


that creates the ability to manipulate the check boxes after the code to insert the columns and rows of the list box...doh! ::)