Liberty BASIC Community Forum
« double mouseclick detection in listview grid »

Welcome Guest. Please Login or Register.
Feb 22nd, 2018, 12:18pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: double mouseclick detection in listview grid  (Read 92 times)
Cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx double mouseclick detection in listview grid
« Thread started on: Feb 17th, 2018, 02:28am »

Hi all,

I am using a listview grid in my program that is based on the working LB listview example I have found.

Within the grid I can select a row and identify its index value - great, I need that.
The example proggy uses buttons to modify the content of the grid (add, delete and update). I want to get rid of the buttons and doubleclick on a selected row to view its related content (the grid's rows are composites based on several other data files.)

Doubleclick detection outside of the grid is no problem. But I can't get that to work within the boundaries of the grid no matter what I try. Searching for an answer by going back even five years does not give an answer to my question.

Can anyone out there help with a working bit of sample code on how to do this? Thanks in advance.

Cor
User IP Logged

metro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 197
xx Re: double mouseclick detection in listview grid
« Reply #1 on: Feb 17th, 2018, 06:13am »

Hi Cor,
have a look here https://lbpe.wikispaces.com/Listview%2C+trapping+double+click


part one
Code:
   'set some globals
    GlOBAL hwndLV,columnIndex,maxrow
    Global   LVS.REPORT, LVS.NOSORTHEADER, LVS.SINGLESEL,_
        LVM.INSERTCOLUMN, LVCF.WIDTH, LVM.INSERTITEM,_
        LVCF.TEXT, LVM.SETITEM, LVIF.TEXT ,LVS.SHOWSELALWAYS,LVM.DELETEITEM

    'set global values
    'constants
    LVS.NOSORTHEADER = 32768
    LVS.REPORT = 1
    LVS.SINGLESEL = 4
    LVS.SHOWSELALWAYS = 8
    LVS.SORTASCENDING = 16
    LVS.SORTDESCENDING = 32
    LVS.NOLABELWRAP = 128
    LVS.AUTOARRANGE = 256
    LVS.NOSCROLL = 8192
    LVS.ALIGNTOP = 0
    LVS.ALIGNLEFT = 2048
    LVS.NOCOLUMNHEADER = 16384
    LVIF.TEXT = 1
    LVIF.STATE = 8
    LVIS.UNSELECTED = 0
    LVIS.FOCUSED = 1
    LVIS.SELECTED = 2
    LVM.FIRST = 4096
    LVM.SETITEM = 4102
    LVM.INSERTITEM = 4103
    LVM.INSERTCOLUMN = 4123
    LVM.GETITEMCOUNT = 4100
    LVM.GETITEMA = 4101
    LVM.GETITEMTEXTA = 4141
    LVM.GETITEMSTATE = 4138
    LVM.SETITEMSTATE = 4139
    LVM.DELETEITEM = 4104
    LVM.DELETEALLITEMS = 4105
    LVCF.WIDTH = 2
    LVCF.TEXT = 4
    'set starting values
    columnIndex=0


    'create structs
    Struct LVCOLUMN, _
        mask As ulong, _
        fmt As long, _
        cx As long, _
        pszText$ As ptr, _
        cchTextMax As long, _
        iSubItem As long, _
        iImage As long, _
        iOrder As long

    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

    struct msg,_
        hndl as ulong,_
        message as long,_
        wParam as long,_
        lParam as long,_
        LOWORDwparam as word,_
        HIWORDwparam as word,_
        LOWORDlparam as word,_
        HIWORDlparam as word

    'initialize common controls:

    calldll #comctl32, "InitCommonControls",re as void

    'set style values
    style = _WS_CHILD OR _WS_VISIBLE OR LVS.NOSORTHEADER Or LVS.REPORT Or LVS.SINGLESEL Or LVS.SHOWSELALWAYS

    'setup window
   nomainwin
BackgroundColor$="darkcyan"

    WindowWidth = 550 : WindowHeight = 400
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
    Menu        #main, "&File" , "E&xit", [quit]
    button #main.b1,"Edit",[editrow],ul,25,5,30,20
    button #main.b2,"Delete",[delete],ul,60,5,40,20
    button #main.b3,"Save List",[saveList],ul,105,5,60,20
    button #main.b4,"Load List",[loadList],ul,170,5,60,20
    button #main.GetMsgHookCallback, "button", [choice], ul, 230, 5, 60, 20
    Open "List View Example" for Window as #main
    #main "trapclose [quit]"

    hWin=hwnd(#main) 'get window handle
    hwndParent = hwnd(#main)

    GOSUB [CREATELISTVIEW]
    GOSUB [ADDCOLUMNS]

    '**************************************************************************************************
    'add data rows
    LVITEM.mask.struct = LVIF.TEXT

    'sample data, i used three spaces to separate each data item
    maxRows=5
    dim rowdata$(maxRows)
    rowdata$(0)="row1   two   three   four   five   six   seven   eight   nine   ten"
    rowdata$(1)="row2   two   three   four   five   six   seven   eight   nine   ten"
    rowdata$(2)="row3   two   three   four   five   six   seven   eight   nine   ten"
    rowdata$(3)="row4   two   three   four   five   six   seven   eight   nine   ten"
    rowdata$(4)="row5   two   three   four   five   six   seven   eight   nine   ten"

    maxrow=maxRows-1

    'add each row of data
    for row=0 to maxrow
        call addRow row, rowdata$(row)
    next
    '**************************************************************************
    open "MsgHook" for dll as #MsgHook
    hMsgProc = hwnd(#main.GetMsgHookCallback)
    calldll #MsgHook, "TrapMsgFor",hwndLV as ulong, ret as boolean
    calldll #MsgHook, "WatchMsg", hwndLV as ulong, _WM_LBUTTONDBLCLK as long, ret as boolean
    hMsgProc = hwnd(#main.GetMsgHookCallback)
    calldll #user32, "GetWindowLongA",hMsgProc as ulong,_GWL_ID as short,callbackID as long
    calldll #MsgHook, "CreateGetMsgProcHook", hwndParent as ulong, callbackID as long, _
        hMsgProc as ulong, hHook as ulong
    'set timer for checking selected listview row

     timer 500, [callsub]
    '*********************************************************************************
   WAIT
 
« Last Edit: Feb 17th, 2018, 06:17am by metro » User IP Logged

Win10 64 HP laptop + desktop Mint Linux 64bit
metro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 197
xx Re: double mouseclick detection in listview grid
« Reply #2 on: Feb 17th, 2018, 06:15am »

part two
Code:
   ''basic save and load routine.------------------------------------------------

[saveList]
    filedialog "Save List","*.txt",saveList$
    if saveList$<>"" then
     open saveList$ for output as #s
     print #s,maxRows
     for s=0 to 5
      print #s,rowdata$(s)
     next s
     close #s
    end if
     notice "List Saved."
    wait

[loadList]
    filedialog "Open List View","*.txt",openFile$
    if openFile$<>"" then
        open openFile$ for input as #i
        input #i,maxRows
        redim rowdata$(maxRows) 'max listview rows.
       for i=0 to maxRows
        line input #i,rowdata$(i)
       next i
        close #i
        maxrow=maxRows-1
       'add each row of data
        for row=0 to maxrow
         call addRow row, rowdata$(row)
        next row
    end if


    '-------------------------------------------------------------------------

[loop]
    Wait

[callsub]

    'call listview1Click ' for future selection using button
    '****************************************************************************************************


    wait


    '----------------edit row window


[editrow]
    timer 0
    WindowWidth = 333 : WindowHeight = 286
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)


    stylebits   #main2.b1, _BS_MULTILINE, 0, 0, 0
    button      #main2.b1, "Save", [saverow], UL, 185, 210, 80, 25
    TextboxColor$ = "White"
    textbox     #main2.t1, 40, 35, 100, 24
    TextboxColor$ = "White"
    textbox     #main2.t2, 40, 70, 100, 24
    TextboxColor$ = "White"
    textbox     #main2.t3, 40, 105, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t4, 40, 140, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t5, 40, 175, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t6, 175, 35, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t7, 175, 70, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t8, 175, 105, 100, 25
    TextboxColor$ = "White"
    textbox     #main2.t9, 175, 140, 100, 24
    TextboxColor$ = "White"
    textbox     #main2.t10, 175, 175, 100, 25

    Open "Edit Row" for Window as #main2
    #main2 "trapclose [quit2]"
    #main2.t1,word$(rowdata$(LVITEM.iItem.struct),1,"   ")
    #main2.t2,word$(rowdata$(LVITEM.iItem.struct),2,"   ")
    #main2.t3,word$(rowdata$(LVITEM.iItem.struct),3,"   ")
    #main2.t4,word$(rowdata$(LVITEM.iItem.struct),4,"   ")
    #main2.t5,word$(rowdata$(LVITEM.iItem.struct),5,"   ")
    #main2.t6,word$(rowdata$(LVITEM.iItem.struct),6,"   ")
    #main2.t7,word$(rowdata$(LVITEM.iItem.struct),7,"   ")
    #main2.t8,word$(rowdata$(LVITEM.iItem.struct),8,"   ")
    #main2.t9,word$(rowdata$(LVITEM.iItem.struct),9,"   ")
    #main2.t10,word$(rowdata$(LVITEM.iItem.struct),10,"   ")


[loop2]

    Wait

[saverow]
    #main2.t1,"!contents? t1$"
    #main2.t2,"!contents? t2$"
    #main2.t3,"!contents? t3$"
    #main2.t4,"!contents? t4$"
    #main2.t5,"!contents? t5$"
    #main2.t6,"!contents? t6$"
    #main2.t7,"!contents? t7$"
    #main2.t8,"!contents? t8$"
    #main2.t9,"!contents? t9$"
    #main2.t10,"!contents? t10$"
    rowdata$(LVITEM.iItem.struct)=trim$(t1$)+"   "+trim$(t2$)+"   "+trim$(t3$)+"   "+trim$(t4$)+"   "+trim$(t5$)+"   "+trim$(t6$)+"   "+trim$(t7$)+"   "+trim$(t8$)+"   "+trim$(t9$)+"   "+trim$(t10$)
    call updaterow rowdata$(LVITEM.iItem.struct)

    goto [quit2]
    wait


[quit2]
    timer 500, [callsub]
    close #main2
    index=0
    wait

[clear]
    wait

[delete]
   call deleteRow LVITEM.iItem.struct
   rc=0:r=0:d=0
    while rc<= maxrow
     if rowdata$(rc)<> rowdata$(LVITEM.iItem.struct) then
      rowdata$(r)=rowdata$(rc)
      r=r+1
     else
      d=d+1
     end if
      rc=rc+1
    wend
    maxrow=maxrow-d
   wait

[quit]
    timer 0
    calldll #MsgHook, "UnhookMsgHook", hHook as ulong, ret as void
    close #MsgHook
    close #main : END

    'subs------------------------------------------------------------------------------------------------

sub deleteRow rn
    CallDLL #user32, "SendMessageA", _
      hwndLV As ulong, _
      LVM.DELETEITEM As long, _
      rn As long, _
      LVITEM As struct, _
      r As long
end sub

sub updaterow rd$
    LVITEM.iSubItem.struct = 0
    LVITEM.pszText$.struct =word$(rd$,1,"   ")
    LVITEM.state.struct=1
    calldll #user32, "SendMessageA" , hwndLV as uLong, LVM.SETITEM as Long,_
     0 As Long, LVITEM As struct, re as Long
    for x=1 to columnIndex-1
      LVITEM.iSubItem.struct = x
      LVITEM.pszText$.struct = word$(rd$,x+1,"   ")
      calldll #user32, "SendMessageA" , hwndLV as uLong, LVM.SETITEM as Long,_
      0 As Long, LVITEM As struct, re as Long
    next x
end sub

'------------------------------------
sub addRow row,rd$
    LVITEM.iItem.struct = row
    LVITEM.iSubItem.struct = 0
    LVITEM.pszText$.struct =word$(rd$,1,"   ")
    calldll #user32, "SendMessageA" , hwndLV as uLong, LVM.INSERTITEM as Long,_
     0 As Long, LVITEM As struct, re as Long
   for x=1 to columnIndex-1
     LVITEM.iItem.struct = row
     LVITEM.iSubItem.struct = x
     LVITEM.pszText$.struct = word$(rd$,x+1,"   ")
     calldll #user32, "SendMessageA" ,hwndLV as uLong, LVM.SETITEM as Long,_
     0 As Long, LVITEM As struct, re as Long
    next x
end sub
'--------------------------------------
sub  addColumn name$
    LVCOLUMN.pszText$.struct = name$
    calldll #user32, "SendMessageA" ,hwndLV as uLong, LVM.INSERTCOLUMN as Long,_
    columnIndex as long, LVCOLUMN as Struct, re as Long
    columnIndex=columnIndex+1
end sub


Sub listview1Click
    LVM.GETITEMA = 4101  : LVM.GETITEMCOUNT = 4100
    LVIF.TEXT = 1        : LVM.GETITEMSTATE = 4138
    LVIS.SELECTED = 2    : LVIF.STATE = 8
    'Returns 0-based index of selected item. Call this routine on a timer
    'with resolution of 1000 ms to see which item is selected.
    calldll #user32, "SendMessageA",hwndLV As uLong,  LVM.GETITEMCOUNT as long,_
     0 as long, 0 as long, total As Long

    For index = 0 To total-1  'check each row
        LVITEM.mask.struct = LVIF.TEXT Or LVIF.STATE
        LVITEM.iItem.struct = row
        LVITEM.iSubItem.struct = 0  'first column
        LVITEM.cchTextMax.struct = 32
        LVITEM.pszText$.struct = Space$(32)
        LVITEM.stateMask.struct = LVIS.SELECTED
        calldll #user32, "SendMessageA", hwndLV As uLong,  LVM.GETITEMA as long,_
        index as long, LVITEM as struct , re As Long
        state = LVITEM.state.struct 'selected s
        If state And LVIS.SELECTED Then
         Exit For
        End If
    Next
End Sub


[choice] 'determine user selection
       calldll #MsgHook, "GetMsg", msg as struct, ret as void
      'get number of items in list:

    CallDLL #user32, "SendMessageA", _
     hwndLV As ulong, _
     LVM.GETITEMCOUNT As long, _
     0 As long, _ 'always 0
     0 As long, _ 'always 0
     total As long
    for index = 0 to total-1 'check each row
     LVITEM.mask.struct = LVIF.TEXT OR LVIF.STATE
     LVITEM.iItem.struct = index 'row
     LVITEM.iSubItem.struct = 0 'first column
     LVITEM.cchTextMax.struct = 32
     LVITEM.pszText$.struct = space$(32)
     LVITEM.stateMask.struct = LVIS.SELECTED
     CallDLL #user32, "SendMessageA", _
      hwndLV As ulong, _
      LVM.GETITEMA As long, _
      index As long, _        'index of row
      LVITEM As struct, _
      r As long
      state = LVITEM.state.struct 'selected state of item
     if state and LVIS.SELECTED then
      txt$=winstring(LVITEM.pszText$.struct)
      goto [editrow]
  '   notice "Selected: ";txt$
     exit for
     end if
    next
      if txt$="" then notice "No selection."
       txt$=""
    wait

[CREATELISTVIEW]
    'create listview control
    calldll #comctl32, "InitCommonControls", re as void
    calldll #user32, "GetWindowLongA", hWin as uLong, _GWL_HINSTANCE as long, hInstance as uLong

    calldll #user32, "CreateWindowExA", _WS_EX_CLIENTEDGE As long,"SysListView32" as ptr,_
     "" as ptr, style as long,  25 as Long,  25 as Long,  500 as Long,  310 as Long,_
     hWin as uLong, 0 as long, hInstance as uLong,"" as ptr, hwndLV As uLong

    calldll #user32, "SendMessageA" , hwndLV as uLong, 4150 as Long,_
     32 As Long, 32 As Long, re as Long    'make listview fullrowselect style
     LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT
     LVCOLUMN.cx.struct = 45 'desired width of column in pixels
 call sendMessage  hwndLV,4150,1,1'SET GRID
   RETURN

[ADDCOLUMNS]
    'add 10 column names, can be changed to match your records comlun names and number of columns

    for c=1 to 10  'add ten columns to the list view
     columnname$="Col";c
    call addColumn columnname$
    next c
    RETURN


function SendMessageLong(hWnd,msg,w,l)
calldll #user32, "SendMessageA", hWnd as ulong, _
msg as long, w as long, l as long,_
SendMessageLong as long
end function

SUB sendMessage  hwndLV , message,wParm ,lParm
    calldll #user32, "SendMessageA",_
        hwndLV as ulong,_
        message as long,_
        wParm as long,_
        lParm as long,_
        re as long
END SUB

 


hope there is something there to help
« Last Edit: Feb 17th, 2018, 06:17am by metro » User IP Logged

Win10 64 HP laptop + desktop Mint Linux 64bit
Cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx Re: double mouseclick detection in listview grid
« Reply #3 on: Feb 17th, 2018, 09:31am »

Metro,

Thanks for a fast reply. I've copied the two parts and will see where I can pickup the requested doubleclick. Before I do, I'll check out the link.

Thanks a lot. No idle hands this weekend! Enjoy yours.

Cor
User IP Logged

metro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 197
xx Re: double mouseclick detection in listview grid
« Reply #4 on: Feb 17th, 2018, 5:08pm »

Cor,
it seems its hard to find the DLL.
try here you may have to join though

https://groups.yahoo.com/neo/groups/libertybasic/files/LaurieM/
User IP Logged

Win10 64 HP laptop + desktop Mint Linux 64bit
Cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 31
xx Re: double mouseclick detection in listview grid
« Reply #5 on: Feb 18th, 2018, 04:31am »

Metro,

Thanks for thinking along with me.

You're right, I needed to register - didn't do that, first checked my backup. I have a quite comprehensive backup of my LB stuff and the dll was among that.

Again thanks.
Cor
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls