Jump to content
AndyS19

Cannot set just 1 listview column's color

Recommended Posts

AndyS19

I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.

My test code is below, but here is the pertinent code:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Local $hWndFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $iDrawStage, $tCustDraw
                    $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
                    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
                    Switch $iDrawStage
                        Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM)
                            setItemColor($tCustDraw, $hWndFrom)
                            Return $CDRF_NOTIFYSUBITEMDRAW
                    EndSwitch
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func setItemColor($tCustDraw, $hWnd)
    Local $iIndex, $color, $iSubitem

    $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number
    $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex)
    $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
    
    ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols
    DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col)
    
    logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _
    & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color))

    DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color
    DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color
EndFunc   ;==>setItemColor

Func logmsg($msg, $lnum = @ScriptLineNumber)
    ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF)
EndFunc   ;==>logmsg


Here is the full test code:

#include-once

;#cs
#NoTrayIcon
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_UseX64=N

Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes)
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)
OnAutoItExitRegister("_test_exit")
Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index
Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

#include <GuiListBox.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>

Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView

Global $hMainWin

test()
Exit

Func test()
    $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1)

    GUICtrlCreateButton("Hwnd", 10, 10, 40, 20)
    GUICtrlSetOnEvent(-1, "handle_1stTEST_btn")

    GUICtrlCreateButton("ID", 50, 10, 40, 20)
    GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn")

    GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit")

    GUISetState(@SW_SHOW)

    While (1)
        Sleep(17)
    WEnd

EndFunc   ;==>test

Func _myColorPicker($obj)
    logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF)
    Local $flags = 0
    Local $ww, $wh, $x, $y, $w, $h

    $__MCP_obj = $obj

    $ww = 350
    $wh = 500
    $x = 200
    $y = 150
    $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags)

    $x = 10
    $y = 10
    $w = 150
    $h = 20
    GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h)
    GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn")

    $y += $h + 5
    $w = $ww - 25
    $h = $wh - 100
    $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    $hListView = GUICtrlGetHandle($idListView)

    $x = $ww / 2 - 50
    $y = $wh - 60
    $w = 100
    $h = 25
    GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h)
    GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn")

    GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new")

    _GUICtrlListView_AddColumn($idListView, "Name", 100)
    _GUICtrlListView_AddColumn($idListView, "Value", 100)
    _GUICtrlListView_AddColumn($idListView, "Sample", 100)
    _GUICtrlListView_SetColumnWidth($idListView, 0, 100)
    _GUICtrlListView_SetColumnWidth($idListView, 1, 80)

    logmsg("+++: $idListView = " & $idListView)
    logmsg("+++: $hListView = 0x" & Hex($hListView))

    __MCP_populateListView($hListView)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState(@SW_SHOW, $__MCP_GUI_hWnd)

EndFunc   ;==>_myColorPicker

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Local $hWndFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $iDrawStage, $tCustDraw
                    $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
                    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
                    Switch $iDrawStage
                        Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM)
                            setItemColor($tCustDraw, $hWndFrom)
                            Return $CDRF_NOTIFYSUBITEMDRAW
                    EndSwitch
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func setItemColor($tCustDraw, $hWnd)
    Local $iIndex, $color, $iSubitem

    $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number
    $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex)
    $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
    
    ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols
    DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col)
    
    logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _
    & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color))

    DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color
    DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color
EndFunc   ;==>setItemColor

Func logmsg($msg, $lnum = @ScriptLineNumber)
    ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF)
EndFunc   ;==>logmsg

Func __MCP_exit()
    GUIDelete($__MCP_GUI_hWnd)
EndFunc   ;==>__MCP_exit

Func __MCP_handle_SetColor_btn()
    If (IsHWnd($__MCP_obj)) Then
        GUISetBkColor($COLOR_BLUE, $__MCP_obj)
    Else
        GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE)
    EndIf
EndFunc   ;==>__MCP_handle_SetColor_btn

Func __MCP_populateListView($hWnd)
    Local $text, $parts, $iIndex

    Local Static $aItems[] = [ _
            "BLACK      | " & $CLR_BLACK & "|" & "", _
            "BLUE       | " & $CLR_BLUE & "|" & "", _
            "RED        | " & $CLR_RED & "|" & "", _
            "WHITE      | " & $CLR_WHITE & "|" & "", _
            "YELLOW     | " & $CLR_YELLOW & "|" & "" _
            ]

    _GUICtrlListView_BeginUpdate($hWnd)
    _GUICtrlListView_DeleteAllItems($hWnd)

    For $ndx = 0 To UBound($aItems) - 1
        $text = $aItems[$ndx]
        $parts = StringSplit($text, "|", 2)
        $parts[0] = StringStripWS($parts[0], 3)
        $parts[2] = StringStripWS($parts[2], 3)

        $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1])
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1)
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2)
    Next

    _GUICtrlListView_EndUpdate($hWnd)
EndFunc   ;==>__MCP_populateListView

Func __MCP_handle_QUIT_btn()
    GUIDelete($__MCP_GUI_hWnd)
EndFunc   ;==>__MCP_handle_QUIT_btn

Func handle_1stTEST_btn()
    _myColorPicker($hMainWin)
EndFunc   ;==>handle_1stTEST_btn

Func handle_2ndTEST_btn()
    _myColorPicker(@GUI_CtrlId)
EndFunc   ;==>handle_2ndTEST_btn

Func _test_exit()
    Exit
EndFunc   ;==>_test_exit

 

Share this post


Link to post
Share on other sites
Danyfirex

hello. Something like this should work...

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $oListView = 0
Example()

Func Example()
    Local $hImage

    ; Create GUI
    GUICreate("ListView Add SubItem", 400, 300)
    $oListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_InsertColumn($oListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($oListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($oListView, 2, "Column 3", 100)

    Local $aItems[] = [ _
            "BLACK      | " & $CLR_BLACK & "|" & "", _
            "BLUE       | " & $CLR_BLUE & "|" & "", _
            "RED        | " & $CLR_RED & "|" & "", _
            "WHITE      | " & $CLR_WHITE & "|" & "", _
            "YELLOW     | " & $CLR_YELLOW & "|" & "" _
            ]

    _GUICtrlListView_BeginUpdate($oListView)
    _GUICtrlListView_DeleteAllItems($oListView)

    For $ndx = 0 To UBound($aItems) - 1
        $text = $aItems[$ndx]
        $parts = StringSplit($text, "|", 2)
        $parts[0] = StringStripWS($parts[0], 3)
        $parts[2] = StringStripWS($parts[2], 3)
        $iIndex = _GUICtrlListView_AddItem($oListView, $parts[0], -1, $parts[1])
        _GUICtrlListView_AddSubItem($oListView, $iIndex, Hex($parts[1]), 1)
        _GUICtrlListView_AddSubItem($oListView, $iIndex, $parts[0], 2)
    Next

    _GUICtrlListView_EndUpdate($oListView)
    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    $g_hListView = GUICtrlGetHandle($oListView)
    Switch $hWndFrom
        Case $g_hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
                    Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                    Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                    Local $iColor = $CLR_BLACK

                    If $iSubItem = 2 Then
                        $iColor = ("0x" & _GUICtrlListView_GetItemText($g_hListView, $iItem, 1))
                    Else
                        $iColor = $CLR_BLACK
                    EndIf

                    DllStructSetData($tCustDraw, "clrText", $iColor)
                    Return $CDRF_NEWFONT

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
AndyS19

Perfect!  I was struggling with 'BugFix's rather extensive UDF code, but this addresses my issue exactly.

 

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

    • Skeletor
      By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • xtcislove
      By xtcislove
      Hello,
      i stuck again,
      Im using this function to create a treeview from root dir.
       
      ;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139 #include <File.au3> #include <WindowsConstants.au3> Global $sPath = @ScriptDir Global $hGui = GUICreate('TreeView-Example', 400, 600) Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE) GUISetState() _CreatePath($sPath, $idTreeView) Do Until GUIGetMsg() = -3 Func _CreatePath($sPath, $idParent) Local $aFolder, $aFiles, $idItem If StringRight($sPath, 1) <> '\' Then $sPath &= '\' $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS) If Not @error Then For $i = 1 To $aFolder[0] $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent) _CreatePath($sPath & $aFolder[$i], $idItem) Next EndIf $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES) If @error Then Return For $i = 1 To $aFiles[0] $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent) Next EndFunc Folder Structure:

      Folder1
      Folder2
      Folder3
      If a file exists in multiple folders, i like to color it red, if not green. 

      I know how to do this for files, but nut for the folders.

      Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

      The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.
       
      Edit:
      Basically i like to color a file and its belonging tree red if the file exists more than 1 time.
    • 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.
×