Jump to content

Recommended Posts

  • 2 weeks later...
Posted (edited)

I need function to edit existing array. I create this code using GUIListViewEx UDF:

#include-once

#include <WindowsConstants.au3> ;$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN
#include <GUIConstantsEx.au3> ;$GUI_EVENT_CLOSE
#include "GUIListViewEx.au3"

ArrayEdit_Example()

Func ArrayEdit_Example()
    Local $aHeaders[] = ["name", "surname", "age"]
    Local $aDataTable[][] = [ ["bill", "gates"], ["jim", "carrey"], ["morgan", "freeman"] ]
    Local $aEditableCols[] = [2]
    ArrayEdit($aDataTable, $aHeaders, $aEditableCols)
    _ArrayDisplay($aDataTable, "$aArrayAfterEditing")
EndFunc

Func ArrayEdit(ByRef $aInput, $aHeaders, $aEditableCols)
    Local Const $GUI_WIDTH = 600
    Local Const $GUI_HEIGHT = 400

    AutoItSetOption("GUICoordMode", default)
    Local $hGUI = GUICreate(Default, $GUI_WIDTH, $GUI_HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN, 8) ;$WS_EX_TOPMOST=8

    Local $idListView = GUICtrlCreateListView(_ArrayToString($aHeaders), 10, 10, $GUI_WIDTH-20, $GUI_HEIGHT-20)

    Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)
    _GUICtrlListView_SetExtendedListViewStyle($idListView, $iExListViewStyle)

    For $i = 0 To UBound($aInput) - 1
        GUICtrlCreateListViewItem(_ArrayToString($aInput, "|", $i, $i), $idListView)
    Next

    $iLV_Index = _GUIListViewEx_Init($idListView, $aInput, 0, 0, True, 512) ;32 = User coloured items, 512 = No internal drag/drop

    Local $sEditableCols = _ArrayToString($aEditableCols, ";")
    _GUIListViewEx_SetEditStatus($iLV_Index, $sEditableCols)
    _GUIListViewEx_MsgRegister(True, False, False)

    GUISetState(@SW_SHOW)

    Local $vRet

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        $vRet = _GUIListViewEx_EventMonitor() ; Use correct monitor function here <<<<<<<<<<<<<<<<<<<
    WEnd
    GUISetState(@SW_HIDE)
    Local $aContentOfListView = _GUIListViewEx_ReturnArray($iLV_Index, 0)
    $aInput = $aContentOfListView
EndFunc

Code is not perfect but I am wondering if you have any tips for me @Melba23 to improve it?

Maybe somewhere there is already function which do the job?

Edited by maniootek
Posted

sometimes if I use the touchpad and swipe left/right to scroll the listview, the scrolling craaaaaawls ever so slowly. This issue doesn't happen if I grab the scrollbar and move to where I want to go. Is this a known thing, is there any programming tricks around that can correct this slowness when swiping with a touchpad?

  • Moderators
Posted (edited)

Champak,

There is no touchpad support in the UDF - and I have no plans to add any.

maniootek,

Just back from a holiday - I will look into your code next week.

M23

31k

Edited by Melba23

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:

  Reveal hidden contents

 

Posted

Ok, i didnt think specific support had to be built for that, I thought I was just seeing a lag/quirk in the way it was scrolling that may have a work around. Np.

  • Moderators
Posted

maniootek,

Perhaps as you are dealing with numbers, you could add an UpDown like this:

#include <WindowsConstants.au3> ;$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN
#include <GUIConstantsEx.au3> ;$GUI_EVENT_CLOSE
#include "GUIListViewEx.au3"

ArrayEdit_Example()

Func ArrayEdit_Example()
    Local $aHeaders[] = ["name", "surname", "age"]
    Local $aDataTable[][] = [ ["bill", "gates"], ["jim", "carrey"], ["morgan", "freeman"] ]
    Local $aEditableCols[] = [2]
    ArrayEdit($aDataTable, $aHeaders, $aEditableCols)
    _ArrayDisplay($aDataTable, "$aArrayAfterEditing")
EndFunc

Func ArrayEdit(ByRef $aInput, $aHeaders, $aEditableCols)
    Local Const $GUI_WIDTH = 600
    Local Const $GUI_HEIGHT = 400

    ;AutoItSetOption("GUICoordMode", default)
    Local $hGUI = GUICreate(Default, $GUI_WIDTH, $GUI_HEIGHT, -1, -1, -1, 8) ;$WS_EX_TOPMOST=8

    Local $idListView = GUICtrlCreateListView(_ArrayToString($aHeaders), 10, 10, $GUI_WIDTH - 20, $GUI_HEIGHT  - 20, $LVS_SHOWSELALWAYS)

    _GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

    For $i = 0 To UBound($aInput) - 1
        GUICtrlCreateListViewItem(_ArrayToString($aInput, "|", $i, $i), $idListView)
        _GUICtrlListView_SetColumnWidth($idListView, $i, 100)
    Next

    $iLV_Index = _GUIListViewEx_Init($idListView, $aInput, 0, 0, True, 512) ;512 = No internal drag/drop

    Local $sEditableCols = _ArrayToString($aEditableCols, ";")
    _GUIListViewEx_SetEditStatus($iLV_Index, $sEditableCols, 1, 1, "1|120|1") :<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    _GUIListViewEx_MsgRegister(True, False, False)

    GUISetState(@SW_SHOW)

    Local $vRet

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        _GUIListViewEx_EventMonitor()
    WEnd

    $aInput = _GUIListViewEx_ReturnArray($iLV_Index, 0)

    GUIDelete($hGUI)

EndFunc

Other than that, I made one or two cosmetic changes which you can take or leave - simply a matter of preferred coding style.

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:

  Reveal hidden contents

 

Posted
  On 10/30/2023 at 7:21 AM, Melba23 said:

maniootek,

Perhaps as you are dealing with numbers, you could add an UpDown like this:

#include <WindowsConstants.au3> ;$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN
#include <GUIConstantsEx.au3> ;$GUI_EVENT_CLOSE
#include "GUIListViewEx.au3"

ArrayEdit_Example()

Func ArrayEdit_Example()
    Local $aHeaders[] = ["name", "surname", "age"]
    Local $aDataTable[][] = [ ["bill", "gates"], ["jim", "carrey"], ["morgan", "freeman"] ]
    Local $aEditableCols[] = [2]
    ArrayEdit($aDataTable, $aHeaders, $aEditableCols)
    _ArrayDisplay($aDataTable, "$aArrayAfterEditing")
EndFunc

Func ArrayEdit(ByRef $aInput, $aHeaders, $aEditableCols)
    Local Const $GUI_WIDTH = 600
    Local Const $GUI_HEIGHT = 400

    ;AutoItSetOption("GUICoordMode", default)
    Local $hGUI = GUICreate(Default, $GUI_WIDTH, $GUI_HEIGHT, -1, -1, -1, 8) ;$WS_EX_TOPMOST=8

    Local $idListView = GUICtrlCreateListView(_ArrayToString($aHeaders), 10, 10, $GUI_WIDTH - 20, $GUI_HEIGHT  - 20, $LVS_SHOWSELALWAYS)

    _GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

    For $i = 0 To UBound($aInput) - 1
        GUICtrlCreateListViewItem(_ArrayToString($aInput, "|", $i, $i), $idListView)
        _GUICtrlListView_SetColumnWidth($idListView, $i, 100)
    Next

    $iLV_Index = _GUIListViewEx_Init($idListView, $aInput, 0, 0, True, 512) ;512 = No internal drag/drop

    Local $sEditableCols = _ArrayToString($aEditableCols, ";")
    _GUIListViewEx_SetEditStatus($iLV_Index, $sEditableCols, 1, 1, "1|120|1") :<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    _GUIListViewEx_MsgRegister(True, False, False)

    GUISetState(@SW_SHOW)

    Local $vRet

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        _GUIListViewEx_EventMonitor()
    WEnd

    $aInput = _GUIListViewEx_ReturnArray($iLV_Index, 0)

    GUIDelete($hGUI)

EndFunc

Other than that, I made one or two cosmetic changes which you can take or leave - simply a matter of preferred coding style.

M23

Expand  

Thank you.

Is it possible to confirm editing by clicking on the any position in the GUI instead of hitting ENTER key?

  • Moderators
Posted

maniootek,

Afraid not - clicking outside the edit control aborts the editing process.

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:

  Reveal hidden contents

 

Posted (edited)

I'm far to be as good as you Melba but you can "save" the edit by clicking away in the GUI like that :

 

#include <WindowsConstants.au3>;$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN
#include <GUIConstantsEx.au3>;$GUI_EVENT_CLOSE
#include "GUIListViewEx.au3"

ArrayEdit_Example()

Func ArrayEdit_Example()
    Local $aHeaders[] = ["name", "surname", "age"]
    Local $aDataTable[][] = [["bill", "gates"], ["jim", "carrey"], ["morgan", "freeman"]]
    Local $aEditableCols[] = [2]
    ArrayEdit($aDataTable, $aHeaders, $aEditableCols)
    _ArrayDisplay($aDataTable, "$aArrayAfterEditing")
EndFunc   ;==>ArrayEdit_Example

Func ArrayEdit(ByRef $aInput, $aHeaders, $aEditableCols)
    Local Const $GUI_WIDTH = 600
    Local Const $GUI_HEIGHT = 400
    Global $iEditMode = 0

    ;AutoItSetOption("GUICoordMode", default)
    Local $hGUI = GUICreate(Default, $GUI_WIDTH, $GUI_HEIGHT, -1, -1, -1, 8) ;$WS_EX_TOPMOST=8

    Local $idListView = GUICtrlCreateListView(_ArrayToString($aHeaders), 10, 10, $GUI_WIDTH - 20, $GUI_HEIGHT - 20, $LVS_SHOWSELALWAYS)

    _GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

    For $i = 0 To UBound($aInput) - 1
        GUICtrlCreateListViewItem(_ArrayToString($aInput, "|", $i, $i), $idListView)
        _GUICtrlListView_SetColumnWidth($idListView, $i, 100)
    Next

;~     $iLV_Index = _GUIListViewEx_Init($idListView, $aInput, 0, 0, True, 512) ;512 = No internal drag/drop

;~     Local $sEditableCols = _ArrayToString($aEditableCols, ";")
;~     _GUIListViewEx_SetEditStatus($iLV_Index, $sEditableCols, 1, 1, "1|120|1") ; :<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    $ReadToArray = _GUIListViewEx_ReadToArray($idListView, 1)
    $idListView_Edit = _GUIListViewEx_Init($idListView, $ReadToArray, 1, 0xFF0000, True, 4 + 64 + 128 + 256 + 512)
    _GUIListViewEx_SetEditStatus($idListView_Edit, "2")

    _GUIListViewEx_MsgRegister(True, False, False)

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        $vRet = _GUIListViewEx_EventMonitor($iEditMode)
        If @error Then
;~ ;~ Do nothing !
        EndIf
        Switch @extended
            Case 1
                If $vRet <> "" Then
                    $row = $vRet[1][0]
                    $column = $vRet[1][1]
                    $before = $vRet[1][2]
                    $after = $vRet[1][3]

                    Switch $column
                        Case 2
                            _GUICtrlListView_SetItemText($idListView, $row, $after, $column)

                    EndSwitch
                EndIf
        EndSwitch
    WEnd

    $aInput = _GUIListViewEx_ReturnArray($idListView_Edit, 0)

    GUIDelete($hGUI)
EndFunc   ;==>ArrayEdit

 

Maybe it's not a good practice... but it works :)

Edited by Resiak1811
  • Moderators
Posted

Resiak1811,

I would strongly advise you NOT to code along those lines. You are amending the ListView content using non-UDF functions (_GUICtrlListView_SetItemText) which means that the  UDF internal array mirroring the ListViewcontent will not reflect the actual content and will, with a very high degree of certainty, result in tears at bedtime.

I have lost track of the number of times I have repeated the mantra: once the UDF is in use you MUST use the UDF functions to amend the ListView content.

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:

  Reveal hidden contents

 

  • 2 months later...
Posted

Hello everyone,


I'm new to /forum.com and old to /forum.fr
I would like to thank Melba23 for his work on the UDF of "GUIListViewEx.au3", very nice work.
And as my presence is new I would like to ask for a small option that could make this beautiful project grow.
Well let's get started, we have a lot of Functions that only deal with Columns, for example:

Func _GUIListViewEx_SetEditStatus($iLV_Index, $vCol, $iMode = 1, $vParam1 = Default, $vParam2 = Default)


But not the Rows, which made me come to this topic and not another because I want to be able to modify the content per ComboBox row with different content on the fly and according to a value to be updated.
Thanks for reading me.

;~ Func _GUIListViewEx_SetEditStatus($iLV_Index, $vRow, $vCol, $iMode = 1, $vParam1 = Default, $vParam2 = Default)

For $i = 0 To $aLV_List_Left[0][0]
    ; ...
    If $_Unit_of_measurement[$i] = $_Unit Then _GUIListViewEx_SetEditStatus( $iLV_Left_Index, $vRow[$j], 5, , 2, "Blue > Red|Blue < Greeen", 1)
    If $_Unit_of_measurement[$i] = $_Unit Then _GUIListViewEx_SetEditStatus( $iLV_Left_Index, $vRow[$j], 5, , 2, "Blue < Red|Blue > Greeen", 1)
    ; ...
Next

 

  • Moderators
Posted (edited)

Anthony72,

This question is better posted in the main UDF thread - I will move it there tomorrow. Moved.

And I must admit that I am having some difficulty understanding exactly what you want as you have 2 identical If constructs so you never get past the first. Should I take it that the $_Unit values in the 2 constructs are actually different variables?

M23 

P.S. Welcome to the AutoIt forums.

Edited by Melba23

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:

  Reveal hidden contents

 

Posted
  Reveal hidden contents

 

Yes indeed I did not see the error and I did not find how to edit here is a very simple test code or when I choose "Standard TV EUROPE" I can have the choice between "NTSC or Pal/Secam/ NTSC" in the right place.

  • Moderators
Posted (edited)

Anthony72,

So you wish to have the ability to crreate an edit combo for a specific row within a column alongside the existing option having the same combo for every row?

If so then I think you will have to use $iMode = 9 to run a custom function when the element is double-clicked. The function will receive the row & column values fo the actioned element and so should be able to produce a dialog with a combo to allow the required selection. I will try and run up an example this afternoon when I have finished installing all the new elements that my wife wants in the bathroom (new mirror, towel rails and cupboards).

M23

Edited by Melba23
Pressed too soon!

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:

  Reveal hidden contents

 

  • Moderators
Posted

Anthony72,

This seems to do what you want:

#include <GuiListBox.au3>
   #include <Date.au3>

#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"
;#include ".\GUIListViewEx\GUIListViewEx.au3"

;~ Global $sRet, $aRetMem

$hGUI = GUICreate("ListView Example_6 Light", 660, 330)

; Create ListView
GUICtrlCreateLabel("ComboBox  - $vRow, $vCol for edit ComboBox (RJ-45) etc...", 10, 10, 400, 20)
$cLV_1 = GUICtrlCreateListView("Country|Reference|Not use|Not use", 10, 30, 640, 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, 158)
Next

; Create Cols & Rows    ; Créer des Colonnes et des Lignes
Global $vCols = 6, $vRows = 4

; Create array and fill listview
Global $aLVArray_1[$vCols][$vRows]

$sData = "RJ-45 color order USA|Blue,Green,Orange,Brown"
$aLVArray_1[0][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)

$sData = "Standard TV USA|NTSC"
$aLVArray_1[1][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)


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

; Set column edit status
_GUIListViewEx_SetEditStatus($iLVIndex_1, "0", 9, _Combo_Edit) ; Call function when double clicked
_GUIListViewEx_SetEditStatus($iLVIndex_1, "1", 9, _Combo_Edit)

$cContent        = GUICtrlCreateButton("Content", 100, 295, 80, 30)
$cHeaders        = GUICtrlCreateButton("Headers", 300, 295, 80, 30)

_GUIListViewEx_MsgRegister()

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit

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

    EndSwitch

    $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

WEnd

Func _Combo_Edit($hLV, $iIndexLV, $iRow, $iCol)

    Local $sCombo_Fill

    ; Select correct combo fill depending on row/col
    Switch $iRow
        Case 0
            Switch $iCol
                Case 0
                    $sCombo_Fill = "RJ-45 color order USA|RJ-45 color order EUROPE"
                Case 1
                    $sCombo_Fill = "Blue,Green,Orange,Brown|Blue,Orange,Green,Brown"
            EndSwitch
        Case 1
            Switch $iCol
                Case 0
                    $sCombo_Fill = "Standard TV USA|Standard TV EUROPE"
                Case 1
                    $sCombo_Fill = "NTSC|Pal/Secam/NTSC"
            EndSwitch
    EndSwitch

    ; Create combo dialog
    $hCombo_Dialog = GUICreate("Edit", 200, 30)

    $cCombo = GUICtrlCreateCombo("", 0, 0, 200, 20)
    ; Fill combo with required elements
    GUICtrlSetData($cCombo, $sCombo_Fill, _GUICtrlListView_GetItemText($hLV, $iRow, $iCol))

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($hCombo_Dialog)
                Return
            Case $cCombo
                ExitLoop
        EndSwitch
    WEnd

    ; Change ListView element to match selection
    _GUIListViewEx_ChangeItem($iIndexLV, $iRow, $iCol, GUICtrlRead($cCombo))

    GUIDelete($hCombo_Dialog)

EndFunc

This is just a very basic example. The combo data selection is a little clunky - I would suggest that it would be more elegant to create an array so that you can get the required data directly using the row/column passed to the function. And you will need to create the dialog with a little more care - such as disabling the main GUI while it is displayed.

I hope that points you in the right direction.

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:

  Reveal hidden contents

 

Posted

Hello Melba23,
I worked a little on the code you gave me and it's pretty good.
I find myself facing the width problem with column 0 and not understood how to solve the problem and make it clean.
Do you have a solution for optimal operation?
Thanks to you.

#include <GuiListBox.au3>
   #include <Date.au3>

#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"
#include ".\GUIListViewEx\GUIListViewEx.au3"

;~ Global $sRet, $aRetMem

$hGUI = GUICreate("ListView Example_6 Light", 660, 330)

; Create ListView
GUICtrlCreateLabel("ComboBox  - $vRow, $vCol for edit ComboBox (RJ-45) etc...", 10, 10, 400, 20)
$cLV_1 = GUICtrlCreateListView("Country|Reference|Not use|Not use", 10, 30, 640, 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, 158)
Next

; Create Cols & Rows    ; Créer des Colonnes et des Lignes
Global $vCols = 6, $vRows = 4

; Create array and fill listview
Global $aLVArray_1[$vCols][$vRows]

$sData = "RJ-45 color order USA|Blue,Green,Orange,Brown"
$aLVArray_1[0][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)

$sData = "Standard TV USA|NTSC"
$aLVArray_1[1][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)


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

; Set column edit status
_GUIListViewEx_SetEditStatus($iLVIndex_1, "0", 9, _Combo_Edit) ; Call function when double clicked
_GUIListViewEx_SetEditStatus($iLVIndex_1, "1", 9, _Combo_Edit)

$cContent        = GUICtrlCreateButton("Content", 100, 295, 80, 30)
$cHeaders        = GUICtrlCreateButton("Headers", 300, 295, 80, 30)

_GUIListViewEx_MsgRegister()

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit

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

    EndSwitch

    $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

WEnd

Func _Combo_Edit( $hLV, $iIndexLV, $iRow, $iCol)
;~    ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "$iRow = "&$iRow &", $iCol = "& $iCol &@CRLF)

    Local $sCombo_Fill

    ; Select correct combo fill depending on row/col
    Switch $iRow
        Case 0
            Switch $iCol
                Case 0
                    $sCombo_Fill = "RJ-45 color order USA|RJ-45 color order EUROPE"
                Case 1
                    $sCombo_Fill = "Blue,Green,Orange,Brown|Blue,Orange,Green,Brown"
            EndSwitch
        Case 1
            Switch $iCol
                Case 0
                    $sCombo_Fill = "Standard TV USA|Standard TV EUROPE"
                Case 1
                    $sCombo_Fill = "NTSC|Pal/Secam/NTSC"
            EndSwitch
    EndSwitch

   ; Retrieve the position x, y and size (width and height) of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetPos.
   Local $aPos = ControlGetPos( $hGUI, "", $hLV)
  ConsoleWrite( "Line=" & @ScriptLineNumber & @TAB & "Position: " & $aPos[0] & ", " & $aPos[1] & ", Size: " & $aPos[2] & ", " & $aPos[3] &@CRLF)

   $aRect = _GUICtrlListView_GetSubItemRect( $hLV, $iRow, $iCol)
   $X = $aPos[0]+$aRect[0]    +2
   $Y = $aPos[1]+$aRect[1]    +2
   $W = $aRect[2]-$aRect[0]
   $H = $aRect[3]-$aRect[1]
   ConsoleWrite( "Line=" & @ScriptLineNumber & @TAB & "$hLV=" & $hLV & ", $iRow=" & $iRow & ", $iCol=" & $iCol & StringFormat(", Subitem Rectangle "&$iRow&","&$iCol&" OK : [%d, %d, %d, %d]", $X, $Y, $W, $Y)&@CRLF)

   ; Create combo dialog
   $hCombo_Dialog = GUICreate( "", $W, $H, -1, -1, BitOR($WS_POPUP, $WS_SYSMENU), $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)

   ; Attach window to the desktop (always on bottom)
   _WinAPI_SetParent( $hCombo_Dialog, $hGUI)

   ; Move GUI 2
   WinMove( $hCombo_Dialog, "", $X, $Y, $W, $H)    ; WinMove( $hCombo_Dialog, "", 150, 100, $aLVPos[2], $aLVPos[3])    X, Y, W, H

   ; Move GUI 2 Combo OK
   Local $aLVPos = WinGetClientSize( $hCombo_Dialog)
   $cCombo = GUICtrlCreateCombo( "", 0, 0, $aLVPos[0], $aLVPos[0])    ; $cCombo = GUICtrlCreateCombo("", 0, 0, 200, 20)

   ; Fill combo with required elements
   GUICtrlSetData( $cCombo, $sCombo_Fill, _GUICtrlListView_GetItemText( $hLV, $iRow, $iCol))

   GUISetState()

   While 1
      Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE, WinActive( $hCombo_Dialog)
            GUIDelete( $hCombo_Dialog)
            Return
         Case $cCombo
            ExitLoop
      EndSwitch
   WEnd

   ; Change ListView element to match selection
   _GUIListViewEx_ChangeItem( $iIndexLV, $iRow, $iCol, GUICtrlRead( $cCombo))

   GUIDelete( $hCombo_Dialog)

EndFunc

 

  • Moderators
Posted

Antony72,

I have run into this problem before - MS likes to give you the entire width of the ListView when you ask for the data of the 0 column. A workaround is to ask for the column width directly:

$W = _GUICtrlListView_GetColumnWidth($hLV, $iCol)

That solves the problem for me.

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:

  Reveal hidden contents

 

Posted

Effectively ...
I'm trying to remove focus from the ListView in order to remove this blue bar but without success, I need a last little help after I'm done with this function.

#include <GuiListBox.au3>
   #include <Date.au3>

#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"
#include ".\GUIListViewEx\GUIListViewEx.au3"

;~ Global $sRet, $aRetMem

$hGUI = GUICreate("ListView Example_6 Light", 660, 330)

; Create ListView
GUICtrlCreateLabel("ComboBox  - $vRow, $vCol for edit ComboBox (RJ-45) etc...", 10, 10, 400, 20)
$cLV_1 = GUICtrlCreateListView("Country|Reference|Not use|Not use", 10, 30, 640, 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, 158)
Next

; Create Cols & Rows    ; Créer des Colonnes et des Lignes
Global $vCols = 6, $vRows = 4

; Create array and fill listview
Global $aLVArray_1[$vCols][$vRows]

$sData = "RJ-45 color order USA|Blue,Green,Orange,Brown"
$aLVArray_1[0][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)

$sData = "Standard TV USA|NTSC"
$aLVArray_1[1][0] = $sData
GUICtrlCreateListViewItem($sData, $cLV_1)


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

; Set column edit status
_GUIListViewEx_SetEditStatus($iLVIndex_1, "0", 9, _Combo_Edit) ; Call function when double clicked
_GUIListViewEx_SetEditStatus($iLVIndex_1, "1", 9, _Combo_Edit)

$cContent        = GUICtrlCreateButton("Content", 100, 295, 80, 30)
$cHeaders        = GUICtrlCreateButton("Headers", 300, 295, 80, 30)

_GUIListViewEx_MsgRegister()

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit

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

    EndSwitch

    $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

WEnd

Func _Combo_Edit( $hLV, $iIndexLV, $iRow, $iCol)
;~    ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "$iRow = "&$iRow &", $iCol = "& $iCol &@CRLF)

    Local $sCombo_Fill

    ; Select correct combo fill depending on row/col
    Switch $iRow
        Case 0
            Switch $iCol
                Case 0
                    $sCombo_Fill = "RJ-45 color order USA|RJ-45 color order EUROPE"
                Case 1
                    $sCombo_Fill = "Blue,Green,Orange,Brown|Blue,Orange,Green,Brown"
            EndSwitch
        Case 1
            Switch $iCol
                Case 0
                    $sCombo_Fill = "Standard TV USA|Standard TV EUROPE"
                Case 1
                    $sCombo_Fill = "NTSC|Pal/Secam/NTSC"
            EndSwitch
    EndSwitch

   ; Retrieve the position x, y and size (width and height) of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetPos.
   Local $aPos = ControlGetPos( $hGUI, "", $hLV)
  ConsoleWrite( "Line=" & @ScriptLineNumber & @TAB & "Position: " & $aPos[0] & ", " & $aPos[1] & ", Size: " & $aPos[2] & ", " & $aPos[3] &@CRLF)

   $aRect = _GUICtrlListView_GetSubItemRect( $hLV, $iRow, $iCol)
   $X = $aPos[0]+$aRect[0]    +2
   $Y = $aPos[1]+$aRect[1]    +1
;~ $W = $aRect[2]-$aRect[0]
   $W = _GUICtrlListView_GetColumnWidth($hLV, $iCol)
   $H = $aRect[3]-$aRect[1] +2
   ConsoleWrite( "Line=" & @ScriptLineNumber & @TAB & "$hLV=" & $hLV & ", $iRow=" & $iRow & ", $iCol=" & $iCol & StringFormat(", Subitem Rectangle "&$iRow&","&$iCol&" OK : [%d, %d, %d, %d]", $X, $Y, $W, $Y)&@CRLF)

   ; Create combo dialog
   $hCombo_Dialog = GUICreate( "", $W, $H, -1, -1, BitOR($WS_POPUP, $WS_SYSMENU), $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)

   ; Attach window to the desktop (always on bottom)
   _WinAPI_SetParent( $hCombo_Dialog, $hGUI)

   ; Move GUI 2
   WinMove( $hCombo_Dialog, "", $X, $Y, $W, $H)    ; WinMove( $hCombo_Dialog, "", 150, 100, $aLVPos[2], $aLVPos[3])    X, Y, W, H

   ; Move GUI 2 Combo OK
   Local $aLVPos = WinGetClientSize( $hCombo_Dialog)
   $cCombo = GUICtrlCreateCombo( "", 0, 0, $aLVPos[0], $aLVPos[0])    ; $cCombo = GUICtrlCreateCombo("", 0, 0, 200, 20)

   ; Fill combo with required elements
   GUICtrlSetData( $cCombo, $sCombo_Fill, _GUICtrlListView_GetItemText( $hLV, $iRow, $iCol))

   ; ---> -------------------------------------------------------------------------------------------------------------------

;~ _GUIListViewEx_BlockReDraw( $cLV_1, True)        ; True  = Prevent redrawing during Insert/Delete/Change calls

   GUICtrlSetState( $cLV_1, $GUI_NOFOCUS)
   ConsoleWrite(  "Line=" & @ScriptLineNumber & @TAB & GUICtrlRead( GUICtrlRead( $cLV_1)) &@CRLF)

;~    For $i = 0 To _GUICtrlListView_GetColumnCount( $hLV)
;~       _GUIListViewEx_SetColour( $cLV_1, ";" , $iRow, $i)    ;    ";" <= par Default    > ";" & $iWhite <=Par couleur
;~    Next

   WinActivate( $hCombo_Dialog, "")

;~ _GUIListViewEx_BlockReDraw( $cLV_1, False)        ; False = Allow future redrawing and force a redraw

   ; <--- -------------------------------------------------------------------------------------------------------------------

   GUISetState()

   While 1
      Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE, WinActive( $hCombo_Dialog)
            GUIDelete( $hCombo_Dialog)
            Return
         Case $cCombo
            ExitLoop
      EndSwitch
   WEnd

   ; Change ListView element to match selection
   _GUIListViewEx_ChangeItem( $iIndexLV, $iRow, $iCol, GUICtrlRead( $cCombo))

   GUIDelete( $hCombo_Dialog)

EndFunc

 

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...