May 05, 2024, 07:05:41 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


In a LISTVIEW

Started by billhsln, November 21, 2007, 12:46:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

Can I have a CHECKBOX and how would I check it's value?  Or how can I select multiple lines in the LISTVIEW and how to tell which ones have been selected?

Example, I have 5 lines showing and I wish to select 1, 3 and 5, but not 2 and 4.  I know I can click on them while holding down the CNTRL key, but how is it handled in EBasic?

Thanks for any help,
Bill
When all else fails, get a bigger hammer.

GJ

Hi Bill,

Don't know if this is what you're looking for, but anyway...  ;)


'Compile as a WINDOWS target

Const LVM_FIRST = 0x1000
Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54)
Const LVS_EX_ONECLICKACTIVATE = 0x40
Const LVS_EX_FULLROWSELECT = 0x020
Const LVS_EX_CHECKBOXES = 0x4 
Const LVS_EX_GRIDLINES = 0x1
Const LVS_EX_HEADERDRAGDROP = 0x10
Const LVM_GETITEMSTATE = (LVM_FIRST + 44)
Const LVM_SETBKIMAGE = (LVM_FIRST + 68)
Const LVIS_STATEIMAGEMASK = 0xF000
Const LVM_SETBKCOLOR = (LVM_FIRST + 1)
Const LVIF_STATE = 0x8
Const LVM_SETITEMSTATE = (LVM_FIRST+43)
Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38)
Const LVBKIF_SOURCE_URL = 0x2
Const LVBKIF_STYLE_NORMAL = 0x0
Const LVBKIF_STYLE_TILE = 0x10


def d1:Dialog
def str,t$:STRING
def p as pointer
int dummy,t,countrows,nstate

'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

DEF mem:MEMORY
DEF lv:NMLISTVIEW 

CREATEDIALOG d1,0,0,295,280,0x80C80080,0,"List view test",&handler
CONTROL d1,@LISTVIEW,"",27,24,240,110,0x50000001,1
CONTROL d1,@BUTTON,"Test",30,200,70,20,0x50000000,2
OPENCONSOLE

domodal d1
end

SUB handler
select @MESSAGE
case @IDINITDIALOG
centerwindow d1
CONTROLCMD d1,1,@LVINSERTCOLUMN,0,"Column1"
CONTROLCMD d1,1,@LVINSERTITEM,0,"Item 1"
CONTROLCMD d1,1,@LVINSERTITEM,1,"Item 2"
CONTROLCMD d1,1,@LVINSERTITEM,2,"Item 3"
CONTROLCMD d1,1,@LVINSERTITEM,3,"Item 4"
CONTROLCMD d1,1,@LVINSERTITEM,4,"Item 5"
        SENDMESSAGE(d1,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_CHECKBOXES|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT,1)

case @IDCONTROL
        IF @CONTROLID=2
           t$=""
           CountRows = CONTROLCMD( d1,1, @LVGETCOUNT) 
           FOR T=0 TO CountRows-1
               IF conLVGetCheckState(d1,1,t)
                  T$=T$+STR$(t+1)
               ENDIF
           NEXT T
           MESSAGEBOX d1,STR$(Countrows)+" rows\n"+t$+" selected","test"
        ENDIF

endselect
return
ENDSUB


SUB conLVGetCheckState(win:WINDOW,cid:INT,index:INT),INT
''Def nState:INT
   'State image 1 is the unchecked box, and state image 2 is the checked box.
   'Setting the state image To zero removes the check box altogether.
   nState=(SENDMESSAGE(win,LVM_GETITEMSTATE,index,LVIS_STATEIMAGEMASK,cid))/4096
   Return (nState=2)
EndSub


Regards,

Gertjan

billhsln

From the looks of the code, I do believe that is exactly what I was looking for.

Thank you so much, Gertjan.  When I get my program done I plan on uploading it here for others to use as an example, so thanks again for the code.

Bill
When all else fails, get a bigger hammer.