Jump to content
nacerbaaziz

create a context menu to listView

Recommended Posts

nacerbaaziz


Hello all
I have a question please
this  a question is about the context menu
When i create a list box  Or combo box
if i create a context menu for this list
When i press the application key or the shortcut shift + f10
the menu options is appear normally
but When i create a List view
if i create a context menu for this list
When i press the application key or the shortcut shift + f10
the menu options isn't appear
But the right mouse button works normally
I need a solution please because I deal with the screen readers users
Unfortunately They can not use the mouse to navigate
So I have to find a solution to activate keyboard shortcuts
am waiting  for your help

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites
JLogan3o13

@nacerbaaziz you know what comes next, you need to provide code that shows the issue you are encountering.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz

hello again
this is my example
When i press the application key or the shortcut shift + f10
the menu options isn't appear
But the right mouse button works normally


#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>
main()
func main()
local $GUI = GUICreate("listView context menu", 800, 400, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)
global $list = GUICtrlCreateListView("", 0, 10, 700, 150, bitOr($LVS_SINGLESEL,$LVS_SORTASCENDING))

    _GUICtrlListView_AddColumn($list, "Name", 150, 0)
    _GUICtrlListView_AddColumn($list, "version", 50, 0)
    _GUICtrlListView_AddColumn($list, "Publisher", 150, 0)
    _GUICtrlListView_AddColumn($list, "Uninstall file path", 400, 0)
local $menu = GUICtrlCreateContextMenu($list)
local $Ref = GUICtrlCreateMenuItem("refresh", $menu)
local $Unins = GUICtrlCreateMenuItem("Uninstall", $menu)
Unins_refresh()
GUISetState(@sw_Show, $GUI)
while 1
Switch GUIGetMSG()
case $GUI_Event_Close
exit
case $Ref
Unins_refresh()
case $Unins
            $selecteditem = _GUICtrlListView_GetItemTextString($list, Int(_GUICtrlListView_GetSelectedIndices($list)))
            $selecteditemarray = StringSplit($selecteditem, "|")

Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(4132,"uninstall " &             $selecteditemarray[1] & "?","are you sure want to uninstall " &             $selecteditemarray[1] & " version" &             $selecteditemarray[2] & "?")
Select
   Case $iMsgBoxAnswer = 6 ;Yes

run($selecteditemarray[4])
EndSelect

EndSwitch
Wend
endFunc
Func Unins_refresh()
    _GUICtrlListView_DeleteAllItems($list)
    ProgressOn("Uninstall Manager", "Loading...", "0%")

local $r_var, $r_hash = 0, $UninsName = "", $UnInsPath = "", $UninsVersion = "", $UninsPublisher = "", $SystemComponent
local $RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
    WEnd
$RegKey = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
###
if @OSArch = "x64" then
$RegKey = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
$RegKey = "HKCU64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then

            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
endIf
endFunc


:)
Please help me

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites
Bilgus

I recently encountered a similar issue with trying to allow update on arrow up and down in a list view

same thing should help you as well

Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 201, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList1_LVN = GUICtrlCreateDummy() ;listview notifications

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

;Event loop etc....
If GuiGetMsg() == $g_hList1_LVN Then
            ;Your Code
EndIf
;;;.................................

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Static Local $hWndList1 = GUICtrlGetHandle($g_hList1)
    If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1)
    If @error Then Return $GUI_RUNDEFMSG
    If $wParam = $g_hList1 Then
        Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

        Switch DllStructGetData($tNMHDR, "Code")

            Case $LVN_KEYDOWN, $NM_CLICK
                GUICtrlSendToDummy($g_hList1_LVN, $lParam)
        EndSwitch
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
































































;

To see it in full context check here:

You also don't really need the dummy control but I wanted to receive an even in my event loop and handle it there rather than in the WM_Notify callback

Noticed I saved the listview handle as well; It seems that sometimes it takes forever for the GUICtrlGetHandle() function to return...

Edited by Bilgus
Made the code post Long so you can use the popup button to get it in a separate window

Share this post


Link to post
Share on other sites
nacerbaaziz

My dear , can you simplify the idea for me please
could  you raise the example in a file please
Because it is somewhat difficult to copy the code using the screen reader
I hope you help me and sorry for the inconvenience

Share this post


Link to post
Share on other sites
Bilgus

Basically you don't get notifications for keypress in the list view so you register a callback for WM_NOTIFY and look for the handle of the listview

This calls the dummy control when it gets a key even or mouse click

in the event for the dummy control you check for a mouse right click or keyboard key and pop your menu

If you want more code than that follow the link and you can see the code in action for the arrow keys

I put the code for DrawPathPoints in a file for you in the example code post..

Edited by Bilgus

Share this post


Link to post
Share on other sites
nacerbaaziz

Frankly I did not understand
I hope you try to EDIT the example THAT I put IN MY Reply
Maybe I understand
I want when I press the Keys previously mentioned THE menu POP-UP appears
Greetings and apologize for the inconvenience

Share this post


Link to post
Share on other sites
JLogan3o13

You have all that code, but don't understand 18 lines that were provided to you? Are you just copying your code from somewhere, without actually understanding what how it works?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
nacerbaaziz
Posted (edited)

hiI understand the code,
but let's say I have more than one list view in the same GUI
so how can I do each list view its own context menu
This is the code that I do, please help me to adjust it.
I apologize for my difficulty in understanding.

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
Global $GUI = GUICreate("test")
Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList1_LVN = GUICtrlCreateDummy()
Global $context = GUICtrlCreateContextMenu($g_hList1_LVN)
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList2_LVN = GUICtrlCreateDummy()
Global $context2 = GUICtrlCreateContextMenu($g_hList2_LVN)
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $g_hList1_LVN
            ShowMenu($GUI, GUIGetMsg(), $context)
    EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Static Local $hWndList1 = GUICtrlGetHandle($g_hList1)
    If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1)
    If @error Then Return $GUI_RUNDEFMSG
    If $wParam = $g_hList1 Then
        Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        Switch DllStructGetData($tNMHDR, "Code")
            Case $LVN_KEYDOWN, $NM_CLICK
                If _IsPressed("02") Or _IsPressed("5D") Then
                    GUICtrlSendToDummy($g_hList1_LVN, $lParam)
                EndIf
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($idContext)

    $aPos = ControlGetPos($hWnd, "", $idCtrl)

    $x = $aPos[0]
    $y = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $tPoint = DllStructCreate("int;int")

    DllStructSetData($tPoint, 1, $x)
    DllStructSetData($tPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

    $x = DllStructGetData($tPoint, 1)
    $y = DllStructGetData($tPoint, 2)
    ; release Struct not really needed as it is a local
    $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

@Bilgus

Edited by Jos
added codebox ... please use that in the future and tidied code

Share this post


Link to post
Share on other sites
Bilgus
Posted (edited)

There is the bare minimum for what you want

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

Global $GUI = GUICreate("test")
Global $g_iTemp
Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy()

Global $context = GUICtrlCreateContextMenu($g_hList1)
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy()
Global $context2 = GUICtrlCreateContextMenu($g_hList2)
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that WM_NOTIFY SENT
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList1, $context)
                Else
                    ConsoleWrite("Some Other Keys" & @CRLF)
                EndIf
            Else
                ConsoleWrite("Some Other Event" & @CRLF)
            EndIf
        Case $g_hList2_LVN
            ConsoleWrite("LV2 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList1_LVN)
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList2, $context2)
                EndIf
            EndIf
    EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR, $iCode ;
    Switch $wParam
        Case $g_hList1
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList1_LVN, $iCode) ;send the code back to be processed by the dummy
            EndSwitch
        Case $g_hList2
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList2_LVN, $iCode)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($idContext)

    $aPos = ControlGetPos($hWnd, "", $idCtrl)

    $x = $aPos[0]
    $y = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $tPoint = DllStructCreate("int;int")

    DllStructSetData($tPoint, 1, $x)
    DllStructSetData($tPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

    $x = DllStructGetData($tPoint, 1)
    $y = DllStructGetData($tPoint, 2)
    ; release Struct not really needed as it is a local
    $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    ;DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $x, $y)
EndFunc   ;==>TrackPopupMenu

 

Edited by Bilgus

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • Broihon
      By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
    • c.haslam
      By c.haslam
      I have
      Local $idListview = GUICtrlCreateListView("",8,8,@DesktopWidth/2-16,@DesktopHeight-150,$LVS_SHOWSELALWAYS, _ $LVS_EX_INFOTIP) Local $hListView = GUICtrlGetHandle($idListview) _GUICtrlListView_InsertColumn($hListview, 0, "Filename", 400) _GUICtrlListView_InsertColumn($hListview, 1, "Ext", 50) _GUICtrlListView_InsertColumn($hListview, 2, "Size",70) _GUICtrlListView_InsertColumn($hListview, 3, 'Date time',100) _GUICtrlListView_InsertColumn($hListview, 4, "Path", 385) _GUICtrlListView_InsertColumn($hListview, 5, "sizeInt", 0) _GUICtrlListView_JustifyColumn($hListview, $kSize,1) ; right align then further on
      While True $sFnamExt = FileFindNextFile($iSrch) If @error Then ExitLoop EndIf $sAtts = FileGetAttrib($sPath&'\'&$sFnamExt) If StringInStr($sAtts,'D') Then If $sFnamExt<>'$RECYCLE.BIN' Then $sDirs &= '?'&$sPath&'\'&$sFnamExt EndIf Else $p = StringInStr($sFnamExt,'.',0,-1) ; last If $p=0 Then $sFnam = $sFnamExt $sExt = '' Else $sFnam = StringLeft($sFnamExt,$p-1) $sExt = StringTrimLeft($sFnamExt,$p) EndIf _GUICtrlListView_AddItem($hListview,$sFnam,-1,_GUICtrlListView_GetItemCount($hListview)+1000) _GUICtrlListView_AddSubItem($hListview,$nItem,$sExt,$kExt) $nSize = FileGetSize($sPath&'\'&$sFnamExt) $sSize = AddThousandsSeparator($nsize) _GUICtrlListView_AddSubItem($hListview,$nItem,$sSize,$kSize) _GUICtrlListView_AddSubItem($hListview,$nItem,$nsize,$kSizeInt) $nTotBytes += $nSize $a1 = FileGetTime($sPath&'\'&$sFnamExt,$FT_MODIFIED,$FT_ARRAY) $t = $a1[0]&'-'&$a1[1]&'-'&$a1[2]&' '&$a1[3]&':'&$a1[4] _GUICtrlListView_AddSubItem($hListview,$nItem,$t,$kDateTime) _GUICtrlListView_AddSubItem($hListview,$nItem,$sPath,$kPath) If $gSQL Then $s = "Insert into tbl values ("&_SQLite_Escape($sFnam)&","&_SQLite_Escape($sExt)&",'"& _ $sSize&"','"& _ $t&"',"&_SQLite_Escape($sPath)&","&$nSize&")" _SQLite_Exec(-1,$s) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf EndIf EndIf WEnd FileClose($iSrch) You will see that I heeded the advice in Help > _GUICtrlListView_AddItem: "As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended."
      (It's unfortunate that the Example does not heed this advice. OK, it doesn't need to because there are no other controls, but still --- it would help neophytes if it did. Also to me _GUICtrlListView_AddItem is not native because it is a UDF. Confused?)
      My script then does a sort using SQLite, and updates the ListView:
      Local $hQuery Local $colNames = ['fnam','ext','nsize','dateTime','path','SizeInt'] Local $s = "Select * FROM tbl ORDER BY "&$colNames[$ncol]&';' _SQLite_Query(-1,$s, $hQuery) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf Local $aRow[$kSizeInt+1] Local $iItem=-1 While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf $iItem += 1 For $i = $kFnam To $kSizeInt _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default) Next WEnd This works, but I had earlier coded
      _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default,$iItem+1000) because the same advice is in the Help for this function.
      So my care in specifying $param back-fired! What am I not understanding?
      The only difference in what works is that the $param parameter is defaulted.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
×