Checking CheckBoxes in a ListView programmatically

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Checking CheckBoxes in a ListView programmatically

Don-3
Hello Everybody,

I'm trying to set CheckBox states in a ListView programmatically. I've found
that I need to send a Windows message to the ListView. Here's the example
from the Windows SDK:

      lResult = SendMessage(      // returns LRESULT in lResult
         (HWND) hWndControl,      // handle to destination control
         (UINT) LVM_SETITEMSTATE,      // message ID
         (WPARAM) wParam,      // = (WPARAM) (int) i;
         (LPARAM) lParam      // = (LPARAM) (LPLVITEM) pitem;
      );


The lParam value is a LVITEM structure. I've tried to set the CheckBox in
this in Smalltalk in a Workspace, but the CheckBox just dissapears. I'm
using Dolphin X6 Professional. I got the hex values from the VB articles in
Google and the commctr.h header file.

Please could someone help? Here's the code:

"Constants used:
LVM_FIRST                          &H1000
LVM_SETITEMSTATE          &H1000 + 43
LVIS_STATEIMAGEMASK  &HF000
LVIF_STATE                          &H8"

lv := ListView show.
lv isVirtual: false.
lv hasCheckBoxes: true.
lv model list: #(1 2 3 4).
lvItem := LVITEM new.
lvItem
     mask: 16r8;   "LVIF_STATE = &H8"
     stateMask: 16r1000;  "LVIS_STATEIMAGEMASK"
     state: 16r2000.       "true"
msg := 16r1000 + 43. "LVM_SETITEMSTATE (LVM_FIRST + 43)"
itemIndex := 1.  "zero based - so should check the 2nd box"
lv sendMessage: msg wParam: itemIndex lParam: lvItem yourAddress.

Thanks in advance for your help.

Don


Reply | Threaded
Open this post in threaded view
|

Re: Checking CheckBoxes in a ListView programmatically

Chris Uppal-3
Don,

> I'm trying to set CheckBox states in a ListView programmatically.

Two previous threads which should help:

    "Checkboxes for ListView"
    Late September 2005

and:

    "How to set a list item screen position?"
    Late January 2004

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Checking CheckBoxes in a ListView programmatically

Don-3
Thanks Chris,

Unfortunately, the first thread doesn't have a method to set the CheckBox
state. It uses ListView>>lvmGetItemState:mask:

I have used the equivalent set method though: ListView>>lvmSetItem:state: ,
which calls the ListView>>sendMessage method.

I've got the code to work in Workspace now. I think I had the wrong
parameters for the LVITEM. Here it is:

LVM_FIRST := 16r1000.
LVM_SETITEMSTATE  := LVM_FIRST + 43.
LVIS_STATEIMAGEMASK  := 16rF000.
LVIF_STATE :=  16r8.
lv := ListView show.
lv isVirtual: false.
lv hasCheckBoxes: true.
lv model list: #(1 2 3 4).
lvItem := LVITEM new.
lvItem
 mask: LVIF_STATE;
 state: 16r2000;   "true"
 stateMask: LVIS_STATEIMAGEMASK.
itemIndex := 1.  "zero based - so should check the 2nd box"
lv view lvmSetItem: itemIndex state: lvItem

The code is based on this VB artice I found, which might help others with
the same question:
http://vbnet.mvps.org/index.html?code/comctl/lvcheckboxgetset.htm

Regards,
Don