Jump to content
Melba23

GUIListViewEx - BugFix Version 15 Sep 20

Recommended Posts

Dear Melba23,

In the context of reloading the ListView, it seems that if we first click some row (select a row), then _GUICtrlListView_DeleteAllItems function seems to make the _EventMonitor to return 9 with a row value of -1, and also column -1

But this is observed only first time (first reloding).

This are the steps to reproduce:

- We first click on some row

- Then reloads the ListView: first time we get 9 wit a -1 row

Better to explain with this example (click the button for reloading to reproduce):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIListViewEx.au3"

$hGUI = GUICreate("", 500, 340)
$cReLoad = GUICtrlCreateButton("Reload ListView", 150, 300, 150, 30)
$cExit = GUICtrlCreateButton("Exit", 350, 300, 110, 30)

; Create ListView
$cLV = GUICtrlCreateListView("Zero Column|One Column|Two Column|Three Column", 10, 30, 480, 260, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV, $i, 100)
Next

;Add data
For $i = 0 To 5
    GUICtrlCreateListViewItem("Item 0-" & $i & "|SubItem 1-" & $i & "|SubItem 2-" & $i & "|SubItem 3-" & $i, $cLV)
Next
;Read the current ListView content
$aLV = _GUIListViewEx_ReadToArray($cLV)
; Inititate the ListView using that content
$iLV = _GUIListViewEx_Init($cLV, $aLV)
;Set all column editable
_GUIListViewEx_SetEditStatus($iLV, "*")

;Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

GUISetState()

;Send a mouse click to the listview
ControlClick($hGUI, "", $cLV)

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $cExit
            Exit
        Case $cReLoad
            Reload_ListView()
    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 1 ; This is returned after an edit attempt
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit" & @CRLF)
            EndIf
        Case 9 ; This is returned after a selection change
            If $vRet[1] = -1 Then MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
    EndSwitch

 WEnd

Func Reload_ListView()
   ;first clear the current content
   _GUICtrlListView_DeleteAllItems($cLV)
   ;close it within the UDF
   _GUIListViewEx_Close(0)
   ;reload the ListView with the same data
   _GUICtrlListView_AddArray($cLV, $aLV)
   ;Initiate LVEx - using same filling array
   _GUIListViewEx_Init($cLV, $aLV)
   ;Set all columns editable
   _GUIListViewEx_SetEditStatus($iLV, "*")
EndFunc

 

Please also let me comment a little doubt, ¿is it possible not returning 9 just after an edit?

It seems that editing always make the _EventMonitor to return 9

 

Many Thanks for your time!

Share this post


Link to post
Share on other sites

robertocm,

I have discovered a few other cases where the UDF returns 9 when it should not. I was trying to prevent these exceptions from firing the "user selection" event, but as there are so many I am now looking to limit the event return to when the user has clicked the mouse or used the arrow keys. The real world is a bit complicated and taking up my time at the moment, but I hope to have something for you to try and break soon.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Dear Melba23,

Many Thanks again, and don't worry to reply soon, for me is fully functional,

I'm always sincerely impressioned by your work in the forum.

Let me share an idea for the future: it should not be difficult to get a transparent label actioning as a highlighting frame that moves following the selected subitem (in short: similar to the visual effect of a selected cell in a excel sheet)

Here a first try:

#include <GuiConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include <StaticConstants.au3>

#include "GUIListViewEx.au3"

;Create GUI
$hGUI = GUICreate("LVEx Example GetLastSel", 640, 510)

$FrameLabel = GUICtrlCreateLabel("", -1, -1, 150, 40, $SS_BLACKFRAME)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

; Create ListView
Global $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)

; Create ListView
Global $cListView_Right = GUICtrlCreateListView("Tom|Dick|Harry", 310, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Right, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Right, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 2, 93)

; Create array and fill Left listview
Global $aLV_List[10]
For $i = 0 To UBound($aLV_List) - 1
    $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Left)
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Right)
Next

; Initiate LVEx
Global $iLV_Index_Left = _GUIListViewEx_Init($cListView_Left, $aLV_List)
_GUIListViewEx_SetEditStatus($iLV_Index_Left, "*")
$iLV_Index_Right = _GUIListViewEx_Init($cListView_Right, $aLV_List)
_GUIListViewEx_SetEditStatus($iLV_Index_Right, "*")

$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

_GUIListViewEx_SetActive($iLV_Index_Left)

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit
    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 1 ; This is returned after an edit attempt
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit" & @CRLF)
            EndIf
        Case 9 ; This is returned after a selection change
            ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
            $aRect = _GUICtrlListView_GetSubItemRect($cListView_Left, $vRet[1], $vRet[2])
            ControlMove($hGUI, "", $FrameLabel, $aRect[0], $aRect[1] + 40, $aRect[2] - $aRect[0], $aRect[3] - $aRect[1])
            ;GUICtrlSetPos($FrameLabel, $aRect[0], $aRect[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1])   ;<< does not work
    EndSwitch

WEnd

 

Share this post


Link to post
Share on other sites

robertocm,

Here is the new version - please try and break it. Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting:

As to the "highlight" idea - it is a complete non-starter. Adding the outline as an overlay is easy, but as soon as the ListView is scrolled everything goes pear-shaped very quickly. That is why scrolling the ListView during an edit operation aborts the edit as it was too difficult to keep the input correctly positioned. And you can already get single cell highlighting (see Example 6) so the whole idea is moot in my eyes.

M23

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

[NEW VERSION] - 1 Aug18

Added:

- Adding items to a native ListView resizes the column to fit the data - the UDF can now retain the original size - look for the $fRetainWidth parameter in _GUIListViewEx_Insert & _GUIListViewEx_InsertSpec.

- _GUIListViewEx_EventMonitor now returns 9 when the user changes the ListView selection - the function returns an array contain the ListView index and the row and column selected.

New version, examples and guide in the first post.

M23

Edited by Melba23
10 years today!!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba,

thanks a lot for your hard  work and for sharing.

Do you know if it is any way to automatically arrange row number after you sort a Listview by clicking on a column?

Thanks in advance.

Share this post


Link to post
Share on other sites

hi @Melba23 thanks  for  this UDF , i try to understund  , but  for my poor mind  is  very complex UDF ,i  have a request  , is  possible  create with this  UDF another  simplify UDF ?

for example  somthing like this  , (the example not work ofcourse (otherwise i got understood :D)) 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <UpDownConstants.au3>
#include <EditConstants.au3>

#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>

#include "GUIListViewEx.au3"

Global $iGreen = "0xCCFFCC"
Global  $cLV_1,$iLVIndex_1
Global $aLVArray_1[6][4]

_main()


Func _main()

Local $sLcolumn="Zero Column|One Column|Two Column|Three Column"
Local $aLDimensPstn="10, 30, 480, 260"
Local $sLBitOR ="BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)"
Local $sLExBitOR = "BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)"

_ListviewPlus($sLcolumn,$aLDimensPstn,$sLBitOR,$sLExBitOR)


$iLVIndex_1 = _GUIListViewEx_Init($cLV_1, $aLVArray_1, 0, 0, True, 1 + 8 + 32) ; + 16

; Create array and fill listview

For $i = 0 To 5
    $sData = "Item " & $i & "-0"
    $aLVArray_1[$i][0] = $sData
    For $j = 1 To 3
        $sData &= "|SubItem " & $i & "-" & $j
        $aLVArray_1[$i][$j] = "SubItem " & $i & "-" & $j
    Next
    GUICtrlCreateListViewItem($sData, $cLV_1)
Next






GUISetState()

EndFunc








Func _ListviewPlus($Column,$DimPst,$BitOr,$BitExOR)

    $cLV_1 = GUICtrlCreateListView($Column,$DimPst ,$BitOr)

_GUICtrlListView_SetExtendedListViewStyle($cLV_1,$BitExOR)


For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV_1, $i, 100)
Next


; Initiate ListView = sort on column click - editable headers - header colours - user colours
$iLVIndex_1 = _GUIListViewEx_Init($cLV_1, $aLVArray_1, 0, 0, True, 1 + 8 + 32) ; + 16

; Set column edit status
_GUIListViewEx_SetEditStatus($iLVIndex_1, 1)                   ; Default = standard text edit
;_GUIListViewEx_SetEditStatus($iLVIndex_1, 2, 2, "1|2|3", True) ; 2 = Read-only combo
;_GUIListViewEx_SetEditStatus($iLVIndex_1, 3, 3)                   ; 3 = DTP

; Create colour array - 0-based to fit ListView content
Global $aLVCol_1[6][4] = [["" & ";" & ""], _            ; Format TxtCol;BkCol
                          [";" & $iGreen, ";" & $iGreen, ";" & $iGreen,";" & $iGreen], _    ; Use leading/trailing ; to indicate if single colour is TxtCol or BkCol
                          [";", "",  "" & ";" & ""]]    ; Default (or no change) can be ";" or ""
; Load colour array into ListView
_GUIListViewEx_LoadColour($iLVIndex_1, $aLVCol_1)
_ArrayDisplay($aLVCol_1)

Global $aHdrData[][] = [[Default, "", "",  ""], _
                        ["", Default, "",  ""], _
                        ["", "", "",  Default], _
                        [0,  0,  Default, 0]]
                        _ArrayDisplay($aLVCol_1)
_GUIListViewEx_LoadHdrData($iLVIndex_1, $aHdrData)




; If colours used then this function must be run BEFORE GUISetState
_GUIListViewEx_MsgRegister()

EndFunc

while 1

    WEnd

 

Share this post


Link to post
Share on other sites

jcpetu,

I am afraid  do not understand your question - the row numbers are automatically reset when the ListView is sorted.

Can you please post a short script showing the problem you are encountering.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

faustf,

What do you want your script to do? If you explain the required end-state I will see if I can get the UDF to do it. Just providing a non-working script with no explanation is not a lot of help.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

hi Thankz  for reply  , i try to understund  this UDF (beast :D ) but   i try to simplify much the example 7 , in practice the final result  i want  , is  a listviewe with  foto in left , and possibility color  line  and  sort  when a click in top of listview 

so the  1 questions is  how is possible insert a foto a this point ?  for example ?

P.S. i belive i finded a buf of scite in last comment #ce #cs  not  colored all green but i think work correctly

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <UpDownConstants.au3>
#include <EditConstants.au3>

#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>

#include "GUIListViewEx.au3"

Global  $iYellow = "0xFFFF00", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0xCCFFCC", _
        $iBlack = "0x000000", _
        $iRed = "0xFF0000", _
        $iBlue = "0x0000FF", _
        $iWhite = "0xFFFFFF"

Global $sRet

$hGUI = GUICreate("Coloured ListView Example", 1000, 510)

; Create ListView
GUICtrlCreateLabel("Full row select - right click item for colour options", 10, 10, 400, 20)
$cLV_1 = GUICtrlCreateListView("Zero Column|One Column|Two Column|Three Column", 10, 30, 480, 260, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

_GUICtrlListView_SetExtendedListViewStyle($cLV_1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP))
For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV_1, $i, 100)
Next

; Create array and fill listview
Global $aLVArray_1[6][4]
For $i = 0 To 5
    $sData = "Item " & $i & "-0"
    $aLVArray_1[$i][0] = $sData
    For $j = 1 To 3
        $sData &= "|SubItem " & $i & "-" & $j
        $aLVArray_1[$i][$j] = "SubItem " & $i & "-" & $j
    Next
    GUICtrlCreateListViewItem($sData, $cLV_1)
Next

; Initiate ListView = sort on column click - editable headers - header colours - user colours
$iLVIndex_1 = _GUIListViewEx_Init($cLV_1, $aLVArray_1, 0, 0, True, 1 + 8 + 32) ; + 16

; Set column edit status
_GUIListViewEx_SetEditStatus($iLVIndex_1, 1)                   ; Default = standard text edit
;_GUIListViewEx_SetEditStatus($iLVIndex_1, 2, 2, "1|2|3", True) ; 2 = Read-only combo
;_GUIListViewEx_SetEditStatus($iLVIndex_1, 3, 3)                   ; 3 = DTP

; Create colour array - 0-based to fit ListView content
Global $aLVCol_1[6][4] = [["" & ";" & ""], _            ; Format TxtCol;BkCol
                          [";" & $iGreen, ";" & $iGreen, ";" & $iGreen,";" & $iGreen], _    ; Use leading/trailing ; to indicate if single colour is TxtCol or BkCol
                          [";", "",  "" & ";" & ""]]    ; Default (or no change) can be ";" or ""
; Load colour array into ListView
_GUIListViewEx_LoadColour($iLVIndex_1, $aLVCol_1)
_ArrayDisplay($aLVCol_1)
;_GUIListViewEx_LoadColour($iLVIndex_1, '0xCCFFCC')

; Set header data
;Global $aHdrData[][] = [["Tom",               "Dick",              "Harry",           "Fred"], _               ; As colour is enabled, these will replace original titles
;                        ["0xFF8080;0x8888FF", "0xFEFEFE;0x000000", "",                "0xFFFF00;0x00FF80"], _  ; Col 2 will use default colours
;                        ["",                  "",                  @TAB & "H1|H2|H3", ""], _                   ; Col 2 readonly combo; Col 1 & 3 text
;                        [0,                   0,                   100,               0]]                      ; Col 2 not resizeable - fixed 100 pixel width

Global $aHdrData[][] = [[Default, "", "",  ""], _
                        ["", Default, "",  ""], _
                        ["", "", "",  Default], _
                        [0,  0,  Default, 0]]
                        _ArrayDisplay($aLVCol_1)
_GUIListViewEx_LoadHdrData($iLVIndex_1, $aHdrData)

#cs
; Create context menu for native ListView
$mContextmenu = GUICtrlCreateContextMenu($cLV_1)
$mWhtTxt = GUICtrlCreateMenuItem("White text", $mContextmenu)
$mYelTxt = GUICtrlCreateMenuItem("Yellow text", $mContextmenu)
$mBluTxt = GUICtrlCreateMenuItem("Cyan text", $mContextmenu)
$mGrnTxt = GUICtrlCreateMenuItem("Green text", $mContextmenu)
$mBlkTxt = GUICtrlCreateMenuItem("Black text", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
$mWhtFld = GUICtrlCreateMenuItem("White field", $mContextmenu)
$mRedFld = GUICtrlCreateMenuItem("Red field", $mContextmenu)
$mBluFld = GUICtrlCreateMenuItem("Blue field", $mContextmenu)
$mGrnFld = GUICtrlCreateMenuItem("Green field", $mContextmenu)
$mBlkFld = GUICtrlCreateMenuItem("Black field", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
$mDefTxt = GUICtrlCreateMenuItem("Default txt", $mContextmenu)
$mDefFld = GUICtrlCreateMenuItem("Default field", $mContextmenu)
$mDefBoth = GUICtrlCreateMenuItem("Default both", $mContextmenu)
#ce
#cs
; Create empty UDF ListView
GUICtrlCreateLabel("Single cell select - use controls below for colour options", 510, 10, 400, 20)
$cLV_2 = _GUICtrlListView_Create($hGUI, "", 510, 30, 480, 260, BitOr($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_BORDER))
_GUICtrlListView_SetExtendedListViewStyle($cLV_2, $LVS_EX_FULLROWSELECT)
; Initiate to get index - empty array passed with no cols so initially set for 1D return array - user coloured items and headers + single cell select
$iLVIndex_2 = _GUIListViewEx_Init($cLV_2, "", 0, 0, True, 32 + 1024) ; 16 +
; Set required colours for ListView elements - change = pink field
Local $aSelCol[4] = [Default, "0xFFCCCC", Default, Default]
_GUIListViewEx_SetDefColours($iLVIndex_2, $aSelCol)
#ce
; Create buttons for LH ListView
#cs
GUICtrlCreateGroup("", 10, 300, 480, 160)

GUICtrlCreateLabel("Up/Down", 25, 320, 80, 20, $SS_CENTER)
$cUp = GUICtrlCreateButton("Up", 25, 340, 80, 30)
$cDown = GUICtrlCreateButton("Down", 25, 380, 80, 30)

GUICtrlCreateLabel("Ins/Del", 150, 320, 80, 20, $SS_CENTER)
$cIns = GUICtrlCreateButton("Ins", 150, 340, 80, 30)
$cDel = GUICtrlCreateButton("Del", 150, 380, 80, 30)

GUICtrlCreateLabel("Ins/Del Spec", 275, 320, 80, 20, $SS_CENTER)
$cInsSpec = GUICtrlCreateButton("Insert Spec", 275, 340, 80, 30)
$cDelSpec = GUICtrlCreateButton("Delete Spec", 275, 380, 80, 30)

GUIStartGroup()
$cRad_Row = GUICtrlCreateRadio(" Row", 160, 425, 40, 20)
GUICtrlSetState($cRad_Row, $GUI_CHECKED)
$cRad_Col = GUICtrlCreateRadio(" Col", 220, 425, 40, 20)
$cSpecChoose = GUICtrlCreateInput(0, 275, 420, 80, 30)
GUICtrlSetFont($cSpecChoose, 18)
GUICtrlCreateUpdown($cSpecChoose, BitOr($UDS_WRAP, $UDS_ALIGNRIGHT))
GUICtrlSetLimit(-1, 9, 0)

GUICtrlCreateLabel("Read", 400, 320, 80, 20, $SS_CENTER)
$cContent = GUICtrlCreateButton("Content", 400, 340, 80, 30)
$cColour = GUICtrlCreateButton("Colour", 400, 380, 80, 30)
$cHeaders = GUICtrlCreateButton("Headers", 400, 420, 80, 30)

; Create colour controls for UDF ListView

GUICtrlCreateGroup("", 510, 300, 480, 160)

GUICtrlCreateLabel("Row", 525, 320, 80, 20, $SS_CENTER)
$cColRow = GUICtrlCreateInput(0, 525, 340, 80, 30, $ES_READONLY)
GUICtrlSetFont($cColRow, 18)
GUICtrlCreateUpdown($cColRow, BitOr($UDS_WRAP, $UDS_ALIGNRIGHT))
GUICtrlSetLimit(-1, 9, 0)

GUICtrlCreateLabel("Column", 640, 320, 80, 20, $SS_CENTER)
$cColCol = GUICtrlCreateInput(0, 640, 340, 80, 30, $ES_READONLY)
GUICtrlSetFont($cColCol, 18)
GUICtrlCreateUpdown($cColCol, BitOr($UDS_WRAP, $UDS_ALIGNRIGHT))
GUICtrlSetLimit(-1, 9, 0)

GUICtrlCreateLabel("Colour", 770, 320, 80, 20, $SS_CENTER)
$cColVal = GUICtrlCreateInput("0x000000", 770, 340, 80, 30, $ES_READONLY)
GUICtrlSetFont($cColVal, 11)
$cColChoose = GUICtrlCreateButton("Select Colour", 770, 380, 80, 30)

GUICtrlCreateLabel("Text/Field", 900, 320, 80, 20)
GUIStartGroup()
$cRad_Txt = GUICtrlCreateRadio(" Text", 900, 340, 80, 20)
GUICtrlSetState($cRad_Txt, $GUI_CHECKED)
$cRad_Fld = GUICtrlCreateRadio(" Field", 900, 380, 80, 20)
GUIStartGroup()

$cSetCol = GUICtrlCreateButton("Set Colour", 525, 380, 195, 30)

$cNewSel = GUICtrlCreateButton("Selected Cell in Orange", 525, 420, 150, 30)
$cDefSel = GUICtrlCreateButton("Selected Cell in  Blue", 700, 420, 150, 30)

; Create additional buttons
$cSave = GUICtrlCreateButton("Save LH ListView", 340, 470, 150, 30)
$cLoad = GUICtrlCreateButton("Load RH ListView", 510, 470, 150, 30)
GUICtrlSetState($cLoad, $GUI_DISABLE)
$cExit = GUICtrlCreateButton("Exit", 880, 470, 110, 30)
#ce
; If colours used then this function must be run BEFORE GUISetState
_GUIListViewEx_MsgRegister()

GUISetState()

;_GUIListViewEx_SetEditKey("^2D")

;MsgBox(0, "Dragging", "You can drag and reorder the headers on the left-hand ListView" & @CRLF & "<----------------------------")

While 1

    $iMsg = GUIGetMsg()
    #cs
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $cExit
            Exit

        Case $cSave
            _GUIListViewEx_SaveListView($iLVIndex_1, "Save.lvs")
            GUICtrlSetState($cLoad, $GUI_ENABLE)
        Case $cLoad
            _GUIListViewEx_LoadListView($iLVIndex_2, "Save.lvs") ; But return now forced to 2D

        Case $cUp
            _GUIListViewEx_SetActive($iLVIndex_1)
            _GUIListViewEx_Up()

        Case $cDown
            _GUIListViewEx_SetActive($iLVIndex_1)
            _GUIListViewEx_Down()

        Case $cIns
            ; Insert row/col
            _GUIListViewEx_SetActive($iLVIndex_1)
            If GUICtrlRead($cRad_Row) = $GUI_CHECKED Then
                _GUIListViewEx_Insert("New Row")
            Else
                _GUIListViewEx_InsertCol("New Col")
            EndIf
        Case $cDel
            ; Delete row/col
            _GUIListViewEx_SetActive($iLVIndex_1)
            If GUICtrlRead($cRad_Row) = $GUI_CHECKED Then
                _GUIListViewEx_Delete()
            Else
                _GUIListViewEx_DeleteCol()
            EndIf

        Case $cInsSpec
            ; Insert spec row/col
            $iValue = GUICtrlRead($cSpecChoose)
            If GUICtrlRead($cRad_Row) = $GUI_CHECKED Then
                _GUIListViewEx_InsertSpec($iLVIndex_1, $iValue, "")
            Else
                _GUIListViewEx_InsertColSpec($iLVIndex_1, $iValue, "New Col")
            EndIf
        Case $cDelSpec
            ; Delete spec row/col
            $iValue = GUICtrlRead($cSpecChoose)
            If GUICtrlRead($cRad_Row) = $GUI_CHECKED Then
                _GUIListViewEx_DeleteSpec($iLVIndex_1, $iValue)
            Else
                _GUIListViewEx_DeleteColSpec($iLVIndex_1, $iValue)
            EndIf

        Case $cContent
            $aRet = _GUIListViewEx_ReturnArray($iLVIndex_1)
            _ArrayDisplay($aRet, "", Default, 8)
        Case $cColour
            $aRet = _GUIListViewEx_ReturnArray($iLVIndex_1, 2)
            _ArrayDisplay($aRet, "", Default, 8)
        Case $cHeaders
            $aRet = _GUIListViewEx_ReturnArray($iLVIndex_1, 4)
            _ArrayDisplay($aRet, "", Default, 8)

        Case $cColChoose
            $sRet = _ChooseColor(2 , 0, 0, $hGUI)
            GUICtrlSetData($cColVal, $sRet)
        Case $cSetCol
            ; Read colour
            $sColSet = GUICtrlRead($cColVal)
            ; Set as text or field
            If GUICtrlRead($cRad_Txt) = $GUI_CHECKED Then
                $sColSet &= ";"
            Else
                $sColSet = ";" & $sColSet
            EndIf
            ; Read location
            $iRow = GUICtrlRead($cColRow)
            $iCol = GUICtrlRead($cColCol)
            ; Set colour
            _GUIListViewEx_SetColour($iLVIndex_2, $sColSet, $iRow, $iCol)

        Case $cNewSel
            ; Set orange field & black text for single cell selection = other colours unchanged
            Local $aSelCol[4] = ["", "", "0x000000", "0xFF8000"]
            _GUIListViewEx_SetDefColours($iLVIndex_2, $aSelCol)
        Case $cDefSel
            ; Reset default white on blue for single cell selection - other colours unchanged
            Local $aSelCol[4] = ["", "", Default, Default]
            _GUIListViewEx_SetDefColours($iLVIndex_2, $aSelCol)

;       Case $mWhtTxt To $mDefBoth
            ; Check context menu items
;           _SetColour($iMsg)

    EndSwitch
#ce

;#cs
    $vRet = _GUIListViewEx_EventMonitor()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 0
            ; No event detected
        Case 1
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8)
            EndIf
        Case 2
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF)
            Else
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8)
            EndIf
        Case 3
            MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF)
        Case 4
            Local $aRet = StringSplit($vRet, ":")
            MsgBox($MB_SYSTEMMODAL, "Dragged", "From ListView " & $aRet[1] & @CRLF & "To ListView " & $aRet[2])
    EndSwitch
;   #ce

WEnd

#cs

Func _SetColour($iCID)

    ; Get information on where last right click occurred within ListView
    Local $aContext = _GUIListViewEx_ContextPos()

    ; Set new colour required
    Local $sColSet = "", $aColArray, $aSplit, $fDef = False
#cs
    Switch $iCID
        Case $mWhtTxt
            $sColSet = $iWhite & ";" ; Text colour followed by ";"
        Case $mYelTxt
            $sColSet = $iYellow & ";"
        Case $mBluTxt
            $sColSet = $iLtBlue & ";"
        Case $mGrnTxt
            $sColSet = $iGreen & ";"
        Case $mBlkTxt
            $sColSet = $iBlack & ";"
        Case $mWhtFld
            $sColSet = ";" & $iWhite ; Field colour preceded by ";"
        Case $mRedFld
            $sColSet = ";" & $iRed
        Case $mBluFld
            $sColSet = ";" & $iBlue
        Case $mGrnFld
            $sColSet = ";" & $iGreen
        Case $mBlkFld
            $sColSet = ";" & $iBlack
        Case $mDefTxt
            ; Get current colours
            $aColArray = _GUIListViewEx_ReturnArray($aContext[0], 2)
            ; Extract current colours
            $aSplit = StringSplit($aColArray[$aContext[1]][$aContext[2]], ";")
            ; Create required setting
            $sColSet = ";" & $aSplit[2]
            ; Set default flag
            $fDef = True
        Case $mDefFld
            $aColArray = _GUIListViewEx_ReturnArray($aContext[0], 2)
            $aSplit = StringSplit($aColArray[$aContext[1]][$aContext[2]], ";")
            $sColSet = $aSplit[1] & ";"
            $fDef = True
        Case $mDefBoth
            $sColSet = ";"
    EndSwitch
#ce
    If $sColSet Then
        ; Reset to default if needed
        If $fDef Then
            _GUIListViewEx_SetColour($aContext[0], ";", $aContext[1], $aContext[2])
        EndIf
        ; Set required item colour
        _GUIListViewEx_SetColour($aContext[0], $sColSet, $aContext[1], $aContext[2])
    EndIf

EndFunc

#ce

 

Share this post


Link to post
Share on other sites

faustf,

If you require icons and photos in your ListView then this UDF is of no use to you as it does not work when they are enabled - sorry.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thankz , so i meet this problem with listviews in autoit , (correct me  if  i mistake), with 

 GUICtrlCreateListViewItem

you can colored but not  can set bmp image , only icon 

with family of this functions _GUICtrlListView  we can insert bmp image but can't  insert  a line colored or column or single cell,

right?

i understund ?

Edited by faustf

Share this post


Link to post
Share on other sites

faustf,

This thread is for questions related to the UDF - please ask general ListView question in the GH&S forum. And I do not know if your understanding is correct as I do not use ListViews with either icons or images.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Dear Melba23,

At the end of the post there  is a new version of the example with an access database. I've been studying hard from your code, and managed to incorporate single cell selection, colours, checkboxes. All the editing of the access table is done directly from the listview.

But first let me suggest another 'idea', I would like a more direct access to the edit mode:

- any alphanumeric character would start editing

+ write the same character in the inputbox

+ don't select all (place the cursor at the end)

From your documentation: this cannot be done in the user script because the UDF suspends the script when starting edit mode.

I suppose that this feature could be included as a new parameter, perhaps in _GUIListViewEx_SetEditKey function

I made some test only to see if this would be possible, and seems to be relatively simple

 

EDITED: code removed (see next post)

 

And finally the example of a listview connected with an access database (does not have any relation whit the previous 'idea')

#include <GuiConstants.au3>
;GUIListViewEx from Melba23  https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16
#include "GUIListViewEx.au3"

Opt("MustDeclareVars", 1)
OnAutoItExitRegister("OnAutoItExit")

;Help: COM Error Handling
Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB")

;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iYellow = "0xFFFF00", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iRed = "0xFF0000", _
        $iBlue = "0x0000FF", _
        $iWhite = "0xFFFFFF"

;_ErrADODB From spudw2k
;https://www.autoitscript.com/forum/topic/105875-adodb-example/
Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB")

Local $sFilePath =  @ScriptDir & "\db.mdb"
Local $sFilePath2 =  @ScriptDir & "\SomeFolder"

Global $sSQL, $w, $Top='', $rstArray, $tblname = "Tel"
;For using fix positions in sql UPDATE
Local $aPosField[9] = ["FieldName1", "FieldName2", "FieldName3", "FieldName4", "FieldName5", "FieldName6", "FieldName7", "FieldName8", "FieldName9"]

Global Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic
Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic
Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable
Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object
Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object
;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilePath
;Global $sADOConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;'
Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123"
$cn.CursorLocation = 3 ; adUseClient

$cn.Open($sADOConnectionString) ; Open the connection

Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

;Create GUI
Global $hGui = GUICreate("Example with access database", $GuiWidth, $GuiHight)
GUISetBkColor(0xA9A9A9)
GUISetIcon("icons\local_gray.ico", 0)
GUISetFont(11, Default, Default, "Segoe UI")

GUICtrlCreateLabel("Activate Edition: [DOUBLE CLICK] or [SPACE BAR].   In Edit Mode: [ENTER] confirm, [ESCAPE] cancel.   In Edit Mode, next cell: [TAB] or [CTRL + ARROWS]", 4, 790, $GuiWidth-10, 31, BitOR($SS_SIMPLE, $SS_SUNKEN))
;GUICtrlSetFont(-1, 11), Default, Default, "Segoe UI")

Global $KeyW = GUICtrlCreateInput("", 4, 1, 205, 33)
GUICtrlSetBkColor(-1, 0xD3D3D3)
GUICtrlSetFont(-1, 11)

Local $cmdRefresh = GUICtrlCreateButton("", $GuiWidth - 315, 1, 60, 34, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 290, 0)
;GUICtrlSetImage(-1, "icons\saved.ico")
Local $Label1 = GUICtrlCreateLabel("Download data >", $GuiWidth - 440, 0, 120, 33)
GUICtrlSetFont(-1, 10)
Global $Label2 = GUICtrlCreateLabel("Next Update " & _HoraProxAct(), $GuiWidth - 230, 1, 245, 33)
GUICtrlSetFont(-1, 10)

;Check if user is not active (for updating from database while user is not active)
;https://stackoverflow.com/questions/3867584/autoit-how-to-get-system-idle-time-or-if-screensaver-is-active
;AutoIt: How to get system idle time, or if screensaver is active?
;The _Timer_GetIdleTime() function uses GetLastInputInfo from user32.dll.
#include <Timers.au3>
Global $iLimit = 15 ; idle limit in seconds
AdlibRegister("_CheckIdleTime", 600000) ;Actualizar datos cada 10 minutos (1000ms/s * 60s/m * 10m), si usuario estuvo inactivo nos últimos 15 segundos (cando se vai facer actualización)

Global $idCheckbox = GUICtrlCreateCheckbox("Filter condition", 212, 1, 259, 33)
GUICtrlSetFont(-1, 9)
GUICtrlSetState(-1, 1) ; checked
Local $cmdFolderTempl = GUICtrlCreateButton("OpenFold", 762, 1, 92, 33, 0)
GUICtrlSetFont(-1, 9)

;This is from Melba23 GUIListViewEx
Local $vRet, $aLV, $iRow, $iCheckState = True
Global $cLV, $iLV, $iEditMode = 22

$cLV = GUICtrlCreateListView("F|Field2|Field3|Field4|Field5|Field6|Field7|Field8|Field9", 2, 35, $GuiWidth-4, 752)
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))

;Set font
GUICtrlSetFont($cLV, 15, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 300)
_GUICtrlListView_SetColumnWidth($cLV, 2, 200)
_GUICtrlListView_SetColumnWidth($cLV, 3, 120)
_GUICtrlListView_SetColumnWidth($cLV, 4, 150)
_GUICtrlListView_SetColumnWidth($cLV, 5, 80)
_GUICtrlListView_SetColumnWidth($cLV, 6, 170)
_GUICtrlListView_SetColumnWidth($cLV, 7, 180)
_GUICtrlListView_SetColumnWidth($cLV, 8, 130)

;Create context menu for native ListView
Local $mContextmenu = GUICtrlCreateContextMenu($cLV)
Local $mWhtFld = GUICtrlCreateMenuItem("White field", $mContextmenu)
Local $mRedFld = GUICtrlCreateMenuItem("Red field", $mContextmenu)
Local $mBluFld = GUICtrlCreateMenuItem("Blue field", $mContextmenu)
Local $mGrnFld = GUICtrlCreateMenuItem("Green field", $mContextmenu)
Local $mBlkFld = GUICtrlCreateMenuItem("Black field", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
Local $mDefFld = GUICtrlCreateMenuItem("Default field", $mContextmenu)

$sSQL = "SELECT FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, FieldName6, FieldName7, FieldName8, FieldName9 FROM " & $tblname & " ORDER BY FieldName2"
$rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ;Issue the SQL query
If Not $rst.EOF = True Then
   $rstArray = $rst.GetRows()
   $rst.Close

   ;Load the ListView with data
   _GUICtrlListView_AddArray($cLV, $rstArray)

   ;Melba23
   ;Set array to give alternate line colouring
   Global $rstCount_1 = Ubound($rstArray)
   Global $rstCount_2 = Ubound($rstArray, 2)
   Global $aColArBand[$rstCount_1][$rstCount_2]
   For $i = 0 To $rstCount_1 - 1
      If Mod($i,2) = 0 Then
         For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xFFFFFF"
         Next
      Else
         For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xE6E6E6"
         Next
      EndIf
      ;Check all items, see examples:
      ;https://www.autoitscript.com/wiki/Snippets_(_Checkboxes_)
      _GUICtrlListView_SetItemChecked($cLV, $i, True)
   Next
   ;Initiate LVEx - using filling array - user colours
   ;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
   $iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)
   ;Prevents ListView redrawing during looped Insert/Delete/Change calls
   ;_GUIListViewEx_BlockReDraw($iLV, True)
   ;Load the required ListView colour array
   Local $aTempColBand = $aColArBand
   ReDim $aTempColBand[UBound($rstArray)][9]
   _GUIListViewEx_LoadColour($iLV, $aTempColBand)
   ;Read the current ListView content
   $aLV = _GUIListViewEx_ReturnArray($iLV, 3)
   ;_ArrayDisplay($aLV, "current content", Default, 8)
   $aLV = $rstArray
   ;Comprobando que coinciden
   ;_ArrayDisplay($rstArray, "recordset content", Default, 8)
   ;Set all columns editable
   _GUIListViewEx_SetEditStatus($iLV, "3-7")
   ;If @error Then Exit MsgBox(0, "", @error)
   ;Initialise tooltip to display 0 column item content for 2 secs when clicked
   _GUIListViewEx_ToolTipInit($iLV, "1", 2000)
Else
   $rst.Close
   ;MsgBox(262144, "", "Non encontrados datos" , 5)
EndIf

;SPACEBAR (but then we have to prevent to change the checbox state)
_GUIListViewEx_SetEditKey("20")
;If @error Then Exit MsgBox(0, "", @error)

;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
;If colours used then this function must be run BEFORE GUISetState
_GUIListViewEx_MsgRegister()

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)
;_GUIListViewEx_BlockReDraw($iLV, False)

GUISetState(@SW_SHOW)
;GUICtrlSetState($cLV, $GUI_FOCUS)
ControlFocus($hGui, "", $cLV)
;ConsoleWrite(ControlGetFocus($hGui))

Local $iMsg
;Help: a bit mask to strip the high word bits from the return of the _WinAPI_GetAsyncKeyState function.
Local Const $iBitMask = 0x8000
While 1
   $iMsg = GUIGetMsg()
   Switch $iMsg
      Case $GUI_EVENT_CLOSE
         $rst = 0 ; Release the recordset object
         $cn.Close ; Close the connection
         $cn = 0 ; Release the connection object
         Exit
      Case $KeyW, $cmdRefresh
         OnFilt()
      Case $cmdFolderTempl
         ShellExecute($sPathPlantillas)
     Case $mWhtFld To $mDefFld
         ;Check context menu items
         _SetColour($iMsg)
   EndSwitch

   $vRet = _GUIListViewEx_EventMonitor($iEditMode)
   ;If @error Then
     ;MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
   ;EndIf
   Switch @extended
      Case 1 ; This is returned after an edit attempt
         ;Restore checked state (because using spacebar for starting the edit mode has the 'disadvantage' of also changing the checked state)
         _GUICtrlListView_SetItemChecked($cLV, $iRow, $iCheckState)
         ;GUICtrlSetState($cLV, $GUI_FOCUS)
         ControlFocus($hGui, "", $cLV)

         If $vRet = "" Then
            ;MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
         Else
            ;_ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8)
            ;MsgBox($MB_SYSTEMMODAL, "", $vRet[1][3])
            ;MsgBox($MB_SYSTEMMODAL, "", _GUIListViewEx_GetLastSelItem())  ;ListViewIndex|Row|Col
            ;updating the access table from the listview
            $sSQL = ''
            For $i = 1 To $vRet[0][0]
               If $sSQL <> '' Then $sSQL = $sSQL & ", "
               ;Treat different text fields and number fields (only for editable columns: 3 to 7)
               Switch $vRet[$i][1]
                  Case 3, 4, 6 To 8
                     If $vRet[$i][3] <> '' Then
                        $sSQL = $sSQL & $aPosField[$vRet[$i][1]] & " = '" & $vRet[$i][3] & "'"
                     Else
                        $sSQL = $sSQL & $aPosField[$vRet[$i][1]] & " = ''"
                     EndIF
                  Case 5
                     If $vRet[$i][3] <> '' Then
                        $sSQL = $sSQL & $aPosField[$vRet[$i][1]] & " = " & $vRet[$i][3]
                     Else
                        $sSQL = $sSQL & $aPosField[$vRet[$i][1]] & " = 0"
                     EndIf
               EndSwitch
            Next
            ;deduct 1 in the row of $aLV because of the different design of both arrays:
               ;_GUIListViewEx_EventMonitor: Total number of edits in [0][0] element --> primeiro valor en F1C0
               ;_GUIListViewEx_ReturnArray ...For mode 2/3: Always 0-based 2D array --> primeiro valor en F0C0
            $sSQL = "UPDATE " & $tblname & " SET " & $sSQL & " WHERE FieldName1 = " & $aLV[$i-1][0]
            $cn.Execute($sSQL, Default, 1 + 0x80)  ;adCmdText = 1 , adExecuteNoRecords = 0x80
            ;ConsoleWrite($sSQL)
         EndIf
      Case 9 ; This is returned after a selection change
         ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
         $iCheckState = _GUICtrlListView_GetItemChecked($cLV, $vRet[1])
         $iRow = $vRet[1]
         If $vRet[2] = 0 Then
            If $iCheckState = True Then
               ToolTip("To Do")
               Sleep(1000)
               ToolTip("")
               $sSQL = "UPDATE " & $tblname & " SET ToDoField = True WHERE FieldName1 = " & $aLV[$iRow][0]
               $cn.Execute($sSQL, Default, 1 + 0x80)  ;adCmdText = 1 , adExecuteNoRecords = 0x80
            EndIf
            ;this is also possible:
            ;$aLV_Check = _GUIListViewEx_ReturnArray($iLV, 1)
            ;If Not @error Then
               ;_ArrayDisplay($aLV_Check, "ListView " & _GUIListViewEx_GetActive() & " State of the checkboxes", Default, 8)
               ;For $i = 0 To Ubound($aLV_Check) - 1
                  ;If $aLV_Check[$i]= True Then Msgbox(0, "Checked", $i)
               ;Next
               ;If $aLV_Check[$vRet[1]] = True Then
                  ;Msgbox(0, "", $vRet[1])
               ;EndIf
            ;Else
               ;MsgBox(0, "Left", "Empty Check Array")
            ;EndIf
         EndIf

   EndSwitch

WEnd

Func OnFilt()
   Local $ToDo
   ;(checked value is 1 and unchecked value is 4)
   ;If GUICtrlRead($idCheckbox) = 1
   If GUICtrlRead($idCheckbox) = $GUI_CHECKED Then
      $w =  " WHERE ToDoField = False"
      $Top = " TOP 100"
   Else
      $w = " WHERE ToDoField = True"
      $Top = ""
      $ToDo = True
   EndIf
   $w = $w & " AND Field2 LIKE '%" & GUICtrlRead($KeyW) & "%' OR Field3 LIKE '%" & GUICtrlRead($KeyW) & "%'"
   $sSQL = "SELECT" & $Top & " FieldName1, FieldName2, FieldName3, FieldName4, FieldName5, FieldName6, FieldName7, FieldName8, FieldName9 FROM " & $tblname & $w & " ORDER BY FieldName2"
   $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ;Issue the SQL query
   If Not @error Then
      If Not $rst.EOF Then
         $rstArray = $rst.GetRows()
         $rst.Close
         ;This seems to cause more flicker
         ;GUISetState(@SW_LOCK)
         ;_GUIListViewEx_BlockReDraw($iLV, True)
         ;reload the ListView with new data, first clear the current content
         _GUICtrlListView_DeleteAllItems($cLV)
         ;close it within the UDF
         _GUIListViewEx_Close(0)
         ;reload the ListView with the new data
         _GUICtrlListView_AddArray($cLV, $rstArray)
         ;Initiate LVEx - using filling array - user colours
         $iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)
         ;Load the required ListView colour array
         Local $rst2Count_1 = UBound($rstArray)
         If $rst2Count_1 <= $rstCount_1 Then
            Local $aTempColBand = $aColArBand
            If $rst2Count_1 < $rstCount_1 Then ReDim $aTempColBand[$rst2Count_1][$rstCount_2]
            For $i = 0 To $rst2Count_1 - 1
               If $ToDo = True Then
                  _GUICtrlListView_SetItemChecked($cLV, $i, True)
               EndIf
            Next
         Else
            Local $aTempColBand[$rst2Count_1][$rstCount_2]
            For $i = 0 To $rst2Count_1 - 1
               If Mod($i,2) = 0 Then
                  For $j = 0 To $rstCount_2 - 1
                     $aTempColBand[$i][$j] = ";0xFFFFFF"
                  Next
               Else
                  For $j = 0 To $rstCount_2 - 1
                     $aTempColBand[$i][$j] = ";0xE6E6E6"
                  Next
               EndIf
               If $ToDo = True Then
                  _GUICtrlListView_SetItemChecked($cLV, $i, True)
               EndIf
            Next
         EndIf
         _GUIListViewEx_LoadColour($iLV, $aTempColBand)
         _GUIListViewEx_SetDefColours($iLV, $aDefCols)
         ;Read the current ListView content
         ;$aLV = _GUIListViewEx_ReturnArray($iLV, 3)
         $aLV = $rstArray
         ;_ArrayDisplay($aLV, "current content", Default, 8)
         ;Set all columns editable
         _GUIListViewEx_SetEditStatus($iLV, "3-7")
         ;Initialise tooltip to display 0 column item content for 2 secs when clicked
         _GUIListViewEx_ToolTipInit($iLV, "1", 2000)
         ;_GUIListViewEx_BlockReDraw($iLV, False)
         ;GUISetState(@SW_UNLOCK)
      Else
         $rst.Close
         SplashTextOn("", "Empty Recordset", 900, -1, -1, -1, 1, "", 24)
         Sleep(4000)
         SplashOff()
      EndIf
   EndIf
GUICtrlSetData($KeyW, "")
;GUICtrlSetState($idCheckbox, $GUI_UNCHECKED)
EndFunc

Func _CheckIdleTime()
   If _Timer_GetIdleTime() > $iLimit * 1000 Then
      ;AdLib functions don't run while a blocking function is shown e.g. MsgBox, InputBox, WinWait, WinWaitClose etc.
      ;MsgBox(16, "Timeout", "You haven't done anything in " & $iLimit & " seconds...  Get busy!")
      OnFilt()
      GUICtrlSetData($Label2, "Next Update: " & _HoraProxAct())
   EndIf
EndFunc

;Author: SmOke_N, _Time()
;https://www.autoitscript.com/wiki/Snippets_(_Time_%26_Date_)
Func _HoraProxAct()
    Local $AMPM, $hour = @HOUR, $min = @MIN + 10
    If $min > 60 Then
        $hour = $hour + 1
        $min = $min - 60
    EndIf
    If $hour > 12 Then
        $hour = $hour - 12
        $AMPM = "PM"
    Else
        $AMPM = "AM"
    EndIf
    Return StringFormat("%02i", $hour) & ":" & StringFormat("%02i", $min) & " " & $AMPM
EndFunc

Func OnAutoItExit()
   ;think this would not be neccesary on exit the script
   ;Unregister the function _CheckIdleTime() from being called every 10 min.
   ;AdlibUnRegister("_CheckIdleTime")
EndFunc

#cs ----------------------------------------------------------------------------
https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
Melba 23, Oct 2017
But here is how you can use the UDF to have a column (2) which uses a combo to limit user edit options
and a right-click menu to select the colour of another column (1) of the selected row.
#ce ----------------------------------------------------------------------------
Func _SetColour($iCID)
    ; Get information on where last right click occurred within ListView
    Local $aContext = _GUIListViewEx_ContextPos()

    ; Set new colour required
    Local $sColSet = "", $aColArray, $aSplit, $fDef = False
    Switch $iCID
        Case $mWhtFld
            $sColSet = $iYellow & ";" & $iWhite ; Text colour followed by ";" Field colour preceded by ";"
        Case $mRedFld
            $sColSet = ";" & $iRed
        Case $mBluFld
            $sColSet = ";" & $iBlue
        Case $mGrnFld
            $sColSet = ";" & $iGreen
        Case $mBlkFld
            ;$sColSet = $iWhite & ";" ; Text colour followed by ";"
            $sColSet = $iWhite & ";" & $iBlack
        Case $mDefFld
            ;Get current colours
            $aColArray = _GUIListViewEx_ReturnArray($aContext[0], 2)
            $aSplit = StringSplit($aColArray[$aContext[1]][$aContext[2]], ";")

            ;Create required setting
            ;Text
            $sColSet = ";" & $aSplit[2]
            ; Set default flag
            $fDef = True

            ;Field
            $sColSet = $aSplit[1] & ";"
            $fDef = True
    EndSwitch

    If $sColSet Then
        ; Reset to default if needed
        If $fDef Then
            _GUIListViewEx_SetColour($aContext[0], ";", $aContext[1], 1)
        EndIf
        ; Set required item colour
        _GUIListViewEx_SetColour($aContext[0], $sColSet, $aContext[1], 1)
    EndIf

EndFunc

Func _ErrADODB()
   Msgbox(0,"ADODB COM Error","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
       "err.description is: "    & @TAB & $errADODB.description    & @CRLF & _
       "err.windescription:"     & @TAB & $errADODB.windescription & @CRLF & _
       "err.number is: "         & @TAB & hex($errADODB.number,8)  & @CRLF & _
       "err.lastdllerror is: "   & @TAB & $errADODB.lastdllerror   & @CRLF & _
       "err.scriptline is: "     & @TAB & $errADODB.scriptline     & @CRLF & _
       "err.source is: "         & @TAB & $errADODB.source         & @CRLF & _
       "err.helpfile is: "       & @TAB & $errADODB.helpfile       & @CRLF & _
       "err.helpcontext is: "    & @TAB & $errADODB.helpcontext _
      , 2)
   Local $err = $errADODB.number
   If $err = 0 Then $err = -1

   ;$rst = 0
   ;$cn.Close
   ;$cn = 0
   ;Exit
EndFunc

 

A final note: i think there's a little mistake in this sentence of the header _GUIListViewEx_EditItem

Remarks: Once edit started, all other script activity is suspended as explained for _GUIListViewEx_EditOnClick

This function is not in the new version of the UDF, as explained in your guide

Many Thanks!

Edited by robertocm

Share this post


Link to post
Share on other sites

robertocm,

Quote

any alphanumeric character would start editing

Please read this announcement to see why your idea is a complete non-starter as it would mean checking for the entire keyboard. You can add such a functionality to your own version if you so wish, but I will not be adding anything like this to the main release. And do you realise that you can set a HotKey to start editing the selected cell via the _GUIListViewEx_SetEditKey function? Is that not sufficient for your purposes?

Quote

 don't select all (place the cursor at the end)

Thisi functionality is already incorporated:

; #FUNCTION# =========================================================================================================
; Name...........: _GUIListViewEx_Init
;[...]
;                  $iAdded    
;[...]
;                               + 2     - Do not "select all" when editing item text
Quote

there's a little mistake in this sentence of the header _GUIListViewEx_EditItem

Fixed to read _GUIListViewEx_EventMonitor - thanks.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Dear Melba23,

Many Thanks for your comments,

Understood, and deleted the code in previous post

1 hour ago, Melba23 said:

do you realise that you can set a HotKey to start editing the selected cell via the _GUIListViewEx_SetEditKey function?

Yes, in fact i'm using this funcion and changed the key to SPACEBAR (reseting the checkbox state after editing)

For me is perfect, but my tool is for users very reluctant to computers (for several reasons you can imagine). They are great proffesionals but avoid computers.

In this context, is easy for them: 'start editing writting any key or number' like in excel sheets. One sentence, all explained.

The 'cursor at the end' was only in this situation (start editing writting the first character)

Many Thanks

Share this post


Link to post
Share on other sites

Melba23,

Hello. I want to ask, how can I change background color of full row using your GUIListViewEx UDF?

I know that change background color for items added to native ListView control using  _GUICtrlListView_AddItem() method is requires some manipulations using WM_NOTIFY or something like that. It's a bit complicated for me right now, so I found that if you using GUICtrlCreateListViewItem() than you can change background color by GUICtrlSetBkColor(). But it's silly in my opinion if i have dynamic flow of row items and if I use some standard UDF functions for manipulating them. So I checked some examples of your GUIListViewEx and came up with simple script (see below in spoiler), where I have only one ListView control with some data, which I initialized with ability to edit and change colors. But in my case I need change color for full row (not for specific item). Can I did it with GUIListViewEx?

Spoiler
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"

$hMainWindow = GUICreate("Main Form", 500, 400, 242, 137)
$cIDEditableListView = GUICtrlCreateListView("", 5, 5, 490, 390, $LVS_REPORT)
_GUIListViewEx_MsgRegister()
GUISetState(@SW_SHOW)

_GUICtrlListView_AddColumn($cIDEditableListView, "#", 30)
_GUICtrlListView_AddColumn($cIDEditableListView, "Name", 150)
_GUICtrlListView_AddColumn($cIDEditableListView, "Version", 100)

_GUICtrlListView_AddItem($cIDEditableListView, "1")
_GUICtrlListView_AddSubItem($cIDEditableListView, 0, "Campaign 1", 1)
_GUICtrlListView_AddSubItem($cIDEditableListView, 0, "1.0", 2)
_GUICtrlListView_AddItem($cIDEditableListView, "2")
_GUICtrlListView_AddSubItem($cIDEditableListView, 1, "Campaign 2", 1)
_GUICtrlListView_AddSubItem($cIDEditableListView, 1, "2.0", 2)

$aLV_Array = _GUIListViewEx_ReadToArray($cIDEditableListView)
$iLV_Index = _GUIListViewEx_Init($cIDEditableListView, $aLV_Array, 0, 0, False, 1 + 32)
_GUIListViewEx_SetEditStatus($iLV_Index, "1-2")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    _GUIListViewEx_EventMonitor()
WEnd

 

 

Share this post


Link to post
Share on other sites

Dear Melba23,

Let me suggest a different approach to the 'idea', using only UDF functions and HotKeySet standard function

This would be the scheme:

Global $cLV, $iLV, $iRow, $iCol, $iEditMode = 22

...

 $vRet = _GUIListViewEx_EventMonitor($iEditMode)

...

Case 9 ; This is returned after a selection change by the user, then listview is active
         HotKeySet("a", "HotKeyPressed")
         HotKeySet("b", "HotKeyPressed")
         HotKeySet("c", "HotKeyPressed")

         $iRow = $vRet[1]
         $iCol = $vRet[2]

...

Func HotKeyPressed()
   ;unregister all (will be registered again in selection change)
   HotKeySet("a")
   HotKeySet("b")
   HotKeySet("c")
   Local $Chr = @HotKeyPressed
   _GUIListViewEx_ChangeItem($iLV, $iRow, $iCol, $Chr)
   _GUIListViewEx_EditItem($iLV, $iRow, $iCol, $iEditMode)
EndFunc

I made some tests and the only issue i'm finding is losing the focus of listview after editing

Many Thanks,

 

@Tersion: see in my example in the previous post, lines from these:

;Melba23
   ;Set array to give alternate line colouring
   Global $rstCount_1 = Ubound($rstArray)
   Global $rstCount_2 = Ubound($rstArray, 2)
   Global $aColArBand[$rstCount_1][$rstCount_2]
   For $i = 0 To $rstCount_1 - 1
      If Mod($i,2) = 0 Then
         For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xFFFFFF"
         Next
      Else
         For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xE6E6E6"
         Next
      EndIf

 

 

 

Edited by robertocm

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...