August 18, 2019, 03:21:46 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Checkboxes in listview - help needed

Started by Haim, July 28, 2007, 01:51:50 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

I saw in the Microsoft documentation for the listview control, that it supports an extended style LVS_EX_CHECKBOXES
As much as I tried to make my listview display checkboxes I failed.
(I tried to do it by using the SetExtendedStyle method of the listview)
I also noted that Aurora user guide does not specify ALVS_EX_CHECKBOXES, but it does specify other extended style constants.

What am i missiing here?

probably brains...

Haim

srod

Hi,

I don't know Aurora as yet, but the following EMBasic example might help.

Code Select
'Compile as a WINDOWS target
/* Required for setting listview checkboxes. */
Const LVM_SETEXTENDEDLISTVIEWSTYLE = 4150
Const LVS_EX_CHECKBOXES = 4

def d1:Dialog
def str:STRING
def p as pointer
'standard NMLISTVIEW
'when a column ic clicked on Windows sends a variable
'of this type in @LPARAM.
TYPE NMLISTVIEW
def hwndFrom:UINT
def idFrom:INT
def code:INT
    def iItem:INT
    def iSubItem:INT
    def uNewState:UINT
    def uOldState:UINT
    def uChanged:UINT
    def ptActionx:INT
def ptActiony:INT
    def lParam:INT
ENDTYPE

CREATEDIALOG d1,0,0,295,168,0x80C80080,0,"List view test",&handler
CONTROL d1,@LISTVIEW,"",27,24,240,110,0x50000001,1
CONTROL d1,@STATIC,"TEST",27,140,240,20,0x50000000,2



domodal d1
end

SUB handler
select @MESSAGE
case @IDINITDIALOG
centerwindow d1
'insert columns and some items
'after an item is inserted we use @LVSETTEXT to
'change the subitems text
CONTROLCMD d1,1,@LVINSERTCOLUMN,0,"Column1"
CONTROLCMD d1,1,@LVINSERTCOLUMN,1,"Column2"
CONTROLCMD d1,1,@LVINSERTITEM,0,"Item 1"
CONTROLCMD d1,1,@LVSETTEXT,0,1,"Subitem 1"
CONTROLCMD d1,1,@LVINSERTITEM,1,"Item 2"
CONTROLCMD d1,1,@LVSETTEXT,1,1,"Subitem 2"
/* Set checkboxes/ */
SendMessage(GETCONTROLHANDLE(d1,1), LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES)
case @IDCONTROL
if(@CONTROLID = 1)
'someone clicked on a column header. Read the data from @LPARAM which is
' a pointer to a NMLISTVIEW UDT. Using the C dereferencing style makes
' it much easier
if(@NOTIFYCODE = @LVNCOLUMNCLICK)
CONTROLCMD d1,1,@LVSETCOLUMNTEXT,*<NMLISTVIEW>@LPARAM.iSubItem,"Clicked!"
endif
ENDIF
endselect
return
ENDSUB



The important line in this case is

Code Select
SendMessage(GETCONTROLHANDLE(d1,1), LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES)

and which should be easy enough to convert to Aurora.

sapero

July 28, 2007, 04:24:28 am #2 Last Edit: July 28, 2007, 05:06:57 am by sapero
In Aurora, just include the windows defines:
Code Select
#include "windows.inc"
#include "commctrl.inc"


Apply the styles to list view:
Code Select
CListView *list = GetControl(IDC_LIST);
list->SetExtendedStyle(LVS_EX_CHECKBOXES);


Check an item:
Code Select
LVITEM lvi;
lvi.stateMask = LVIS_STATEIMAGEMASK;
lvi.state     = 0x2000; // pass 0 to uncheck
SendMessage(list->m_hwnd, LVM_SETITEMSTATE, item_index, &lvi);


get the check state:
Code Select
BOOL checked = (0x2000 & SendMessage(list->m_hwnd, LVM_GETITEMSTATE, item_index, LVIS_STATEIMAGEMASK));

Haim

Thank you both for your replies.
I have seen the Ebasic sample but could not make it work in Aurora....
With Sapero's reply my problems are over.


with much appreciation,

Haim

sapero

I'm very sorry, the latest SendMessage should be AND'ed with 0x2000.