Jump to content

ListView Edit (ok)+ Combo (probleme)


jresine
 Share

Recommended Posts

Original code :  https://www.autoitscript.com/forum/topic/75406-listview-subitems-edit-in-place-by-double-click/

 

Hello , I have a problem with this code , the edit control works perfectly, but the combo control does not work, someone would have an idea of where the problem come ?

Thanks in advance.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <GuiComboBoxEx.au3>

Opt("GuiCloseOnESC", 0)

Global $hEdit, $hCombo, $Item = -1, $SubItem = 0

Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $WS_BORDER, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("ListView Subitems edit in place", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                        If $aHit[1] == 1 Then
                            $hEdit = _GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 1, $aRect[1] - 4, $aRect[2] - $aRect[0], 20, $Style)
                            _WinAPI_SetFocus($hEdit)
                        ElseIf $aHit[1] == 2 Then
                            $hCombo = _GUICtrlComboBoxEx_Create($hGUI,$iSubItemText & "|test 1|texte 2| fin 3", $aRect[0] + 1, $aRect[1] - 4, $aRect[2] - $aRect[0], 20, $Style)
                            _WinAPI_SetFocus($hCombo)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
        Case $hCombo
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlComboBoxEx_GetEditText($hCombo)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DestroyWindow($hCombo)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

JR.

Edited by jresine
Link to comment
Share on other sites

  • Moderators

jresine,

I would suggest using my GUIListViewEx UDF instead - much easier to code:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIListViewEx.au3"

Opt("GuiCloseOnESC", 0)

$hGUI = GUICreate("ListView Subitems edit in place", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUISetState()

; Read ListView contents
$aListViewContent = _GUIListViewEx_ReadToArray($hListView)
; Initialise ListView
$iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "1;2")
; Set combo data for the required column
_GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3")
; Register required messages
_GUIListViewEx_MsgRegister()

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    ; Look for the edit doubleclicks
    _GUIListViewEx_EditOnClick()
WEnd

You can find the link in my sig.

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

 

Link to comment
Share on other sites

  • Moderators

jresine,

You just use the normal AutoIt functions to change the basic ListView attributes - GUICtrlSetColor/BkColor/Font for native ListViews or the equivalent _GUICtrlListView_* functions for the UDF-created ones . As you create the control you can set it up as you wish, all the UDF does is look after the 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:

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

 

Link to comment
Share on other sites

Hello , yes I know, but what I would like is a color per cell. I used this code in my script :

_WinAPI_SetFont($list,_WinAPI_CreateFont(20,0),False)

and this for cell background color :

Func WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam)
    Local $tNMHDR,$hWndFrom,$iCode
    $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam)
    $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom")
    $iCode = DllStructGetData($tNMHDR,"Code")
    Switch $hWndFrom
        Case $list
            Switch $iCode
                Case -12
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage")
                    Switch $iDrawStage
                        Case 0x00000001
                            Return 0x00000020
                        Case 0x00010001
                            Return 0x00000020
                    EndSwitch
                    Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec")
                    Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem")
                    Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7
                    If $iSubItem == 0 Then
                        If _GUICtrlListView_GetItemText($list,$iItem,0) == "" Then
                            DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7)
                        EndIf
                    EndIf
                    If $iSubItem == 7 Then
                        If _GUICtrlListView_GetItemText($list,$iItem,7) <> 0 Then
                            DllStructSetData($tCustDraw,"clrTextBk",0x0000FF)
                        EndIf
                    EndIf
                    If $iSubItem == 8 Then
                        If _GUICtrlListView_GetItemText($list,$iItem,0) == "" Then
                            DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7)
                        Else
                            DllStructSetData($tCustDraw,"clrTextBk",0xffffff)
                        EndIf
                    EndIf
                    Return 0x00000002
........

 

Edited by jresine
Link to comment
Share on other sites

  • Moderators

jresine,

This thread popped up when I searched for "ListView colour". You did try that before posting I suppose?

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

 

Link to comment
Share on other sites

Yes, I have tested. But the colors "bug" without refresh the window.

Also the functions listview edit and combo is broken :/

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include<GuiListView.au3>
#include "GUIListViewEx.au3"
#include<WinAPI.au3>

Opt("GuiCloseOnESC", 0)

$hGUI = GUICreate("ListView Subitems edit in place", 300, 300)

$hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 0, 0, 300, 300,$LVS_REPORT)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
_WinAPI_SetFont($hListView,_WinAPI_CreateFont(20,0),False)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next



GUISetState()

$aListViewContent = _GUIListViewEx_ReadToArray($hListView)
$iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "*")
_GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3",True)


_GUIListViewEx_MsgRegister()

GUIRegisterMsg(0x004E,"WM_NOTIFY")

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    ; Look for the edit doubleclicks
    _GUIListViewEx_EditOnClick()
WEnd

Func WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam)
    Local $tNMHDR,$hWndFrom,$iCode
    $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam)
    $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom")
    $iCode = DllStructGetData($tNMHDR,"Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case -12
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage")
                    Switch $iDrawStage
                        Case 0x00000001
                            Return 0x00000020
                        Case 0x00010001
                            Return 0x00000020
                    EndSwitch
                    Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec")
                    Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem")
                    Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7
                    If $iSubItem == 0 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7)
                    EndIf
                    If $iSubItem == 1 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0x0000FF)
                    EndIf
                    If $iSubItem == 2 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0xffffff)
                    EndIf
                    Return 0x00000002
            EndSwitch
    EndSwitch
EndFunc

JR.

Link to comment
Share on other sites

  • Moderators

jresine,

Also the functions listview edit and combo is broken :/

As explained in the UDF headers, you do not use the _GUIListViewEx_MsgRegister function if you already have the relevant message handlers - you need to add the UDF handler function(s) inside the existing handler(s).

But the colors "bug" without refresh the window

Perhaps post in that thread to see if there is a fix?

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

 

Link to comment
Share on other sites

Good morning !

OK, it work. But the listview does not turn while "gray" in the edition . Can we repair or disable it ?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include<GuiListView.au3>
#include "GUIListViewEx.au3"
#include<WinAPI.au3>

Opt("GuiCloseOnESC", 0)

$hGUI = GUICreate("ListView Subitems edit in place", 300, 300)

$hListView = _GUICtrlListView_Create($hGUI, "Items|EDIT|COMBO", 0, 0, 300, 300,$LVS_REPORT)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
_WinAPI_SetFont($hListView,_WinAPI_CreateFont(20,0),False)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

$aListViewContent = _GUIListViewEx_ReadToArray($hListView)
$iLV_Index = _GUIListViewEx_Init($hListView, $aListViewContent, 0, 0, True, 2 + 16, "*")
_GUIListViewEx_ComboData($iLV_Index, 2, "Choice 1|Choice 2|Choice 3",True)

GUIRegisterMsg(0x004E,"WM_NOTIFY")
GUIRegisterMsg(0x0200, "_GUIListViewEx_WM_MOUSEMOVE_Handler")
GUIRegisterMsg(0x0202, "_GUIListViewEx_WM_LBUTTONUP_Handler")

GUISetState()

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    _GUIListViewEx_EditOnClick()
WEnd

Func WM_NOTIFY($hWnd,$iMsg,$iwParam,$ilParam)
    _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR,$hWndFrom,$iCode
    $tNMHDR = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct",$ilParam)
    $hWndFrom = DllStructGetData($tNMHDR,"hWndFrom")
    $iCode = DllStructGetData($tNMHDR,"Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case -12
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW,$ilParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw,"dwDrawStage")
                    Switch $iDrawStage
                        Case 0x00000001
                            Return 0x00000020
                        Case 0x00010001
                            Return 0x00000020
                    EndSwitch
                    Local $iItem = DllStructGetData($tCustDraw,"dwItemSpec")
                    Local $iSubItem = DllStructGetData($tCustDraw,"iSubItem")
                    Local $hDC = DllStructGetData($tCustDraw,'hdc') ;f7f7f7
                    If $iSubItem == 0 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0xf7f7f7)
                    EndIf
                    If $iSubItem == 1 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0x0000FF)
                    EndIf
                    If $iSubItem == 2 Then
                        DllStructSetData($tCustDraw,"clrTextBk",0xffffff)
                    EndIf
                    Return 0x00000002
            EndSwitch
    EndSwitch
EndFunc

 

Link to comment
Share on other sites

  • Moderators

jresine,

I am stuck in Madrid airport at the moment (such fun!) - I will look into the problem over the weekend.

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

 

Link to comment
Share on other sites

  • Moderators

jresine,

Back home again after the delay.

But the listview does not turn while "gray" in the edition

I am unsure what you mean - can you please expand a bit.

And you slightly misunderstood the registering - you can still use the  _GUIListViewEx_MsgRegister  function for the other messages - like this:

GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")
_GUIListViewEx_MsgRegister(False)

Now the WM_MOUSEMOVE & WM_LBUTTONUP messages are registered but the previous WM_NOTIFY handler is not overwritten.

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...