Jump to content



Photo

GUICtrlCreateListView


  • Please log in to reply
52 replies to this topic

#1 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 11 November 2010 - 12:44 PM

hello guys

i wanne make a GUICtrlCreateListView but if i click on a item i wanne be able to typ in the field.

how this can me done?

Greetz Yucatan







#2 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 11 November 2010 - 02:21 PM

yucatan,

This thread shows you how to do it. :(

Come back if you have problems integrating the code into your script. :graduated:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#3 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 11 November 2010 - 02:28 PM

yucatan,

This thread shows you how to do it. :(

Come back if you have problems integrating the code into your script. :graduated:

M23

yeah i'm having some truble to integrating my code.

i use this code now
Plain Text         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flag to indicate double click in ListView Global $fDblClk = False $Gui = GUICreate("Test", 400, 250) ; This works with either type of ListView - just adjust the comment statements to change the type ;#cs $hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) GUICtrlCreateListViewItem("Item 1", $hListView) GUICtrlCreateListViewItem("Item 2", $hListView) GUICtrlCreateListViewItem("Item 3", $hListView) GUICtrlCreateListViewItem("Item 4", $hListView) ;#ce #cs $hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) _GUICtrlListView_AddItem($hListView, "Item 1",0) _GUICtrlListView_AddItem($hListView, "Item 2",2) _GUICtrlListView_AddItem($hListView, "Item 3",1) _GUICtrlListView_AddItem($hListView, "Item 4",3) #ce GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $fDblClk = False         If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)         $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)         If $iSelected <> "" Then _GUICtrlListView_EDITLabel($hListView, $iSelected)     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $hWndListView = $hListView     If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hWndListView             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = True                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then Return True             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc


i when i stop editing the field.

i wanne execute some code.

but now is my question.
where should i put the code that i want to be executed?
how can i use this code if i have 6 different listview in my gui?

Edited by yucatan, 11 November 2010 - 02:35 PM.


#4 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 11 November 2010 - 02:39 PM

yucatan,

I would use another flag to indicate that the editing had ended - something like this (look for the <<<<<<<<<<<< lines): :graduated:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flags to indicate: 1) double click in ListView 2) editing ended Global $fDblClk = False, $fEdited = False ; <<<<<<<<<<<<<<<<<<<<<<<<<<< $Gui = GUICreate("Test", 400, 250) $hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) GUICtrlCreateListViewItem("Item 1", $hListView) GUICtrlCreateListViewItem("Item 2", $hListView) GUICtrlCreateListViewItem("Item 3", $hListView) GUICtrlCreateListViewItem("Item 4", $hListView) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $fDblClk = False         If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)         $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)         If $iSelected <> "" Then _GUICtrlListView_EditLabel($hListView, $iSelected)     EndIf     ; Editing has ended so run the code     If $fEdited Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<         $fEdited = False         MsgBox(0, "Hi there", "A label was edited")     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $hWndListView = $hListView     If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hWndListView             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = True                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<                         Return True                     EndIf             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc

That way you get back from the message handler as soon as possible, which is always a good idea. :(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#5 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 11 November 2010 - 02:46 PM

yucatan,

I would use another flag to indicate that the editing had ended - something like this (look for the <<<<<<<<<<<< lines): :graduated:

AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flags to indicate: 1) double click in ListView 2) editing ended Global $fDblClk = False, $fEdited = False ; <<<<<<<<<<<<<<<<<<<<<<<<<<< $Gui = GUICreate("Test", 400, 250) $hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) GUICtrlCreateListViewItem("Item 1", $hListView) GUICtrlCreateListViewItem("Item 2", $hListView) GUICtrlCreateListViewItem("Item 3", $hListView) GUICtrlCreateListViewItem("Item 4", $hListView) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $fDblClk = False         If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)         $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)         If $iSelected <> "" Then _GUICtrlListView_EditLabel($hListView, $iSelected)     EndIf     ; Editing has ended so run the code     If $fEdited Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<         $fEdited = False         MsgBox(0, "Hi there", "A label was edited")     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $hWndListView = $hListView     If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hWndListView             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = True                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<                         Return True                     EndIf             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc

That way you get back from the message handler as soon as possible, which is always a good idea. :(

M23



how can i use this code if i have 6 different listview in my gui?
how can i define and lokc the width of my listview items?
how can i find out wich field had been edited?

greetz yucatan

Edited by yucatan, 11 November 2010 - 03:02 PM.


#6 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 11 November 2010 - 03:11 PM

yucatan,

Did your mother never tell you to say "Please" and "Thank you" occasionally? :D

Here is the code adjusted to work with 2 ListViews with headers which cannot be adjusted: :graduated:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flags to indicate: 1) double click in ListView 2) editing ended Global $fDblClk = 0, $fEdited = False $hGUI = GUICreate("Test", 400, 250) $hListView_1 = GUICtrlCreateListView("Items", 2, 2, 196, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) $hLV_1_Handle = GUICtrlGetHandle(-1) ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hLV_1_Handle))) ; Disable ListView header <<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateListViewItem("Item 1", $hListView_1) GUICtrlCreateListViewItem("Item 2", $hListView_1) GUICtrlCreateListViewItem("Item 3", $hListView_1) GUICtrlCreateListViewItem("Item 4", $hListView_1) $hListView_2 = GUICtrlCreateListView("Items", 202, 2, 196, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) $hLV_2_Handle = GUICtrlGetHandle(-1) ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hLV_2_Handle))) GUICtrlCreateListViewItem("Item 5", $hListView_2) GUICtrlCreateListViewItem("Item 6", $hListView_2) GUICtrlCreateListViewItem("Item 7", $hListView_2) GUICtrlCreateListViewItem("Item 8", $hListView_2) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         Switch $fDblClk ; Depending on the ListView clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             Case 1                 $iSelected = _GUICtrlListView_GetSelectedIndices($hLV_1_Handle)                 If $iSelected <> "" Then _GUICtrlListView_EditLabel($hLV_1_Handle, $iSelected)             Case 2                 $iSelected = _GUICtrlListView_GetSelectedIndices($hLV_2_Handle)                 If $iSelected <> "" Then _GUICtrlListView_EditLabel($hLV_2_Handle, $iSelected)         EndSwitch         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         MsgBox(0, "Hi there", "A label was edited")     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hLV_1_Handle             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = 1 ; Set the flag to indicate the ListView which was doubleclicked <<<<<<<<<<<<<<<<<<<<<<<                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True                         Return True                     EndIf             EndSwitch         Case $hLV_2_Handle             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = 2                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True                         Return True                     EndIf             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc

Adding the other 4 ListViews I leave as an exercise for the student - as my old maths master used to say! :D

But if I had 6 ListViews to deal with, I would put the ListView handles into an array and so shorten the code significantly. :D

Any other requests? :(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#7 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 11 November 2010 - 03:44 PM

yucatan,

Did your mother never tell you to say "Please" and "Thank you" occasionally? :D

Here is the code adjusted to work with 2 ListViews with headers which cannot be adjusted: :graduated:

AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flags to indicate: 1) double click in ListView 2) editing ended Global $fDblClk = 0, $fEdited = False $hGUI = GUICreate("Test", 400, 250) $hListView_1 = GUICtrlCreateListView("Items", 2, 2, 196, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) $hLV_1_Handle = GUICtrlGetHandle(-1) ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hLV_1_Handle))) ; Disable ListView header <<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateListViewItem("Item 1", $hListView_1) GUICtrlCreateListViewItem("Item 2", $hListView_1) GUICtrlCreateListViewItem("Item 3", $hListView_1) GUICtrlCreateListViewItem("Item 4", $hListView_1) $hListView_2 = GUICtrlCreateListView("Items", 202, 2, 196, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT)) $hLV_2_Handle = GUICtrlGetHandle(-1) ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hLV_2_Handle))) GUICtrlCreateListViewItem("Item 5", $hListView_2) GUICtrlCreateListViewItem("Item 6", $hListView_2) GUICtrlCreateListViewItem("Item 7", $hListView_2) GUICtrlCreateListViewItem("Item 8", $hListView_2) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         Switch $fDblClk ; Depending on the ListView clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             Case 1                 $iSelected = _GUICtrlListView_GetSelectedIndices($hLV_1_Handle)                 If $iSelected <> "" Then _GUICtrlListView_EditLabel($hLV_1_Handle, $iSelected)             Case 2                 $iSelected = _GUICtrlListView_GetSelectedIndices($hLV_2_Handle)                 If $iSelected <> "" Then _GUICtrlListView_EditLabel($hLV_2_Handle, $iSelected)         EndSwitch         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         MsgBox(0, "Hi there", "A label was edited")     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hLV_1_Handle             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = 1 ; Set the flag to indicate the ListView which was doubleclicked <<<<<<<<<<<<<<<<<<<<<<<                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True                         Return True                     EndIf             EndSwitch         Case $hLV_2_Handle             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = 2                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True                         Return True                     EndIf             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc

Adding the other 4 ListViews I leave as an exercise for the student - as my old maths master used to say! :D

But if I had 6 ListViews to deal with, I would put the ListView handles into an array and so shorten the code significantly. :D

Any other requests? :(

M23




yeah i have some other requets.

sorry i forgot to say thanks u

this are my other requestst:)

how can i define the width of my listview items?
how can i find out wich field had been edited?

Edited by yucatan, 11 November 2010 - 03:50 PM.


#8 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 11 November 2010 - 04:44 PM

yucatan,

OK, last answer for today! :(

You need to use the ListView UDF to get the row and column. So here you have 6 ListViews with 2 columns and I have used an array to store the handles as I suggested earlier. Only problem - you can only edit the first column. As far as I know that is the best you can do with the $LVS_EDITLABELS style. :graduated:

Here is the script:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flags to indicate: 1) double click in ListView, 2) editing ended Global $fDblClk = 0, $fEdited = False Global $sEdited_Cell = "" Global $aLV_Handles[7] $hGUI = GUICreate("Test", 600, 400) For $i = 1 To 3     For $j = 0 To 1         $hListView = _GUICtrlListView_Create($hGUI, "Items", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))         $aLV_Handles[$i + ($j * 3)] = $hListView         _GUICtrlListView_AddColumn($hListView, "SubItems")         ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))         _GUICtrlListView_SetColumnWidth($hListView, 0, 150)         _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)         For $k = 1 To 4             _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)             _GUICtrlListView_AddSubItem($hListView, $k - 1, $k, 1)         Next     Next Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         Local $aHit = _GUICtrlListView_SubItemHitTest($aLV_Handles[$fDblClk])         If $aHit[0] <> -1 Then             If $aHit[1] Then                 MsgBox(0, "Hi there", "ListView " & $fDblClk & " : Row " & $aHit[0] + 1 & @CRLF & "is not editable")             Else                 _GUICtrlListView_EditLabel($aLV_Handles[$fDblClk], $aHit[0])                 $sEdited_Cell = "ListView " & $fDblClk & " : Row " & $aHit[0] + 1 & @CRLF & "has been edited"             EndIf         EndIf         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         MsgBox(0, "Hi there", $sEdited_Cell)         $sEdited_Cell = ""     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")     $iCode = DllStructGetData($tNMHDR, "Code")     For $i = 1 To 6         If $aLV_Handles[$i] = $hWndFrom Then             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = $i                 Case $LVN_BEGINLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Return False                 Case $LVN_ENDLABELEDITW                     Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)                     Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _                         DllStructGetData($tInfo, "Text"))                     Local $sNewText = DllStructGetData($tBuffer, "Text")                     If StringLen($sNewText) Then                         $fEdited = True                         Return True                     EndIf             EndSwitch             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc

I will go and look at how we might edit other items - you try and work out what I have done! :D

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#9 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 12 November 2010 - 03:08 PM

yucatan,

That was fun! :D

You can thank smashly for this as it is his code I have modified - and you can thank me for my searching and integration efforts. With this version you are now able to edit all the items and subitems in the ListViews: :graduated:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include <GuiEdit.au3> Global $fDblClk = 0, $fEdited = 0 Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit Global $iListView_ID, $sItemText Global $aLV_Handles[7] Global $hGUI = GUICreate("Test", 600, 400) For $i = 1 To 3     For $j = 0 To 1         $hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)         _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)         $aLV_Handles[$i + ($j * 3)] = $hListView         _GUICtrlListView_AddColumn($hListView, "Col 2")         _GUICtrlListView_AddColumn($hListView, "Col 3")         ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))         _GUICtrlListView_SetColumnWidth($hListView, 0, 60)         _GUICtrlListView_SetColumnWidth($hListView, 1, 60)         _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)         For $k = 1 To 4             _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)         Next     Next Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $hListView = $aLV_Handles[$fDblClk]         $iListView_ID = $fDblClk         $aHit = _GUICtrlListView_SubItemHitTest($hListView)         If $aHit[0] <> -1 Then             _Start_ItemEdit()         EndIf         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & @CRLF & "has been altered" & @CRLF)     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     #forceref $hWnd, $iMsg, $wParam     Local $hWndFrom, $iCode, $tNMHDR     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iCode = DllStructGetData($tNMHDR, "Code")     For $i = 1 To 6         If $aLV_Handles[$i] = $hWndFrom Then             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = $i             EndSwitch             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)     #forceref $hWnd, $Msg, $wParam     Local $iCode = BitShift($wParam, 16)     Switch $lParam         Case $hEdit             Switch $iCode                 Case $EN_KILLFOCUS                     _End_SubItemEdit()             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc   ;==>WM_COMMAND Func _Start_ItemEdit()     $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])     Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])     Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])     Local $aPos = WinGetPos($hListView)     Local $tPoint = DllStructCreate("int X;int Y")     DllStructSetData($tPoint, "X", $aPos[0])     DllStructSetData($tPoint, "Y", $aPos[1])     _WinAPI_ScreenToClient($hGUI, $tPoint)     Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]     Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]     $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))     _GUICtrlEdit_SetSel($hEdit, 0, -1)     _WinAPI_SetFocus($hEdit)     $hDC = _WinAPI_GetWindowDC($hEdit)     $hBrush = _WinAPI_CreateSolidBrush(0)     Local $stRect = DllStructCreate("int;int;int;int")     DllStructSetData($stRect, 1, $iLen + 10)     DllStructSetData($stRect, 2, 0)     DllStructSetData($stRect, 3, 0)     DllStructSetData($stRect, 4, 17)     DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc Func _End_SubItemEdit()     Local $sText = _GUICtrlEdit_GetText($hEdit)     If $sText <> $sItemText Then         _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])         $fEdited = True     EndIf     _WinAPI_DeleteObject($hBrush)     _WinAPI_ReleaseDC($hEdit, $hDC)     _WinAPI_DestroyWindow($hEdit)     $hListView = 0 EndFunc

Is that everything you wanted? :(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#10 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 15 November 2010 - 01:00 PM

Hello,

in your other sample i was able to push enter en then it saved my edit.
what is the best say to implement this here?



yucatan,

That was fun! :D

You can thank smashly for this as it is his code I have modified - and you can thank me for my searching and integration efforts. With this version you are now able to edit all the items and subitems in the ListViews: :graduated:

AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include <GuiEdit.au3> Global $fDblClk = 0, $fEdited = 0 Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit Global $iListView_ID, $sItemText Global $aLV_Handles[7] Global $hGUI = GUICreate("Test", 600, 400) For $i = 1 To 3     For $j = 0 To 1         $hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)         _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)         $aLV_Handles[$i + ($j * 3)] = $hListView         _GUICtrlListView_AddColumn($hListView, "Col 2")         _GUICtrlListView_AddColumn($hListView, "Col 3")         ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))         _GUICtrlListView_SetColumnWidth($hListView, 0, 60)         _GUICtrlListView_SetColumnWidth($hListView, 1, 60)         _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)         For $k = 1 To 4             _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)         Next     Next Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $hListView = $aLV_Handles[$fDblClk]         $iListView_ID = $fDblClk         $aHit = _GUICtrlListView_SubItemHitTest($hListView)         If $aHit[0] <> -1 Then             _Start_ItemEdit()         EndIf         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & @CRLF & "has been altered" & @CRLF)     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     #forceref $hWnd, $iMsg, $wParam     Local $hWndFrom, $iCode, $tNMHDR     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iCode = DllStructGetData($tNMHDR, "Code")     For $i = 1 To 6         If $aLV_Handles[$i] = $hWndFrom Then             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = $i             EndSwitch             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)     #forceref $hWnd, $Msg, $wParam     Local $iCode = BitShift($wParam, 16)     Switch $lParam         Case $hEdit             Switch $iCode                 Case $EN_KILLFOCUS                     _End_SubItemEdit()             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc   ;==>WM_COMMAND Func _Start_ItemEdit()     $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])     Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])     Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])     Local $aPos = WinGetPos($hListView)     Local $tPoint = DllStructCreate("int X;int Y")     DllStructSetData($tPoint, "X", $aPos[0])     DllStructSetData($tPoint, "Y", $aPos[1])     _WinAPI_ScreenToClient($hGUI, $tPoint)     Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]     Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]     $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))     _GUICtrlEdit_SetSel($hEdit, 0, -1)     _WinAPI_SetFocus($hEdit)     $hDC = _WinAPI_GetWindowDC($hEdit)     $hBrush = _WinAPI_CreateSolidBrush(0)     Local $stRect = DllStructCreate("int;int;int;int")     DllStructSetData($stRect, 1, $iLen + 10)     DllStructSetData($stRect, 2, 0)     DllStructSetData($stRect, 3, 0)     DllStructSetData($stRect, 4, 17)     DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc Func _End_SubItemEdit()     Local $sText = _GUICtrlEdit_GetText($hEdit)     If $sText <> $sItemText Then         _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])         $fEdited = True     EndIf     _WinAPI_DeleteObject($hBrush)     _WinAPI_ReleaseDC($hEdit, $hDC)     _WinAPI_DestroyWindow($hEdit)     $hListView = 0 EndFunc

Is that everything you wanted? :(

M23


Edited by yucatan, 15 November 2010 - 01:07 PM.


#11 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 15 November 2010 - 01:34 PM

yucatan,

I would use an Accelerator key - these are like HotKeys but only work within your app rather than on all running processes. You could code it like this - look for the <<<<<<<<<<<<<<< lines: :graduated:
AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include <GuiEdit.au3> Global $fDblClk = 0, $fEdited = False Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit Global $iListView_ID, $sItemText Global $aLV_Handles[7] Global $hGUI = GUICreate("Test", 600, 500) For $i = 1 To 3     For $j = 0 To 1         $hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)         _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)         $aLV_Handles[$i + ($j * 3)] = $hListView         _GUICtrlListView_AddColumn($hListView, "Col 2")         _GUICtrlListView_AddColumn($hListView, "Col 3")         ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))         _GUICtrlListView_SetColumnWidth($hListView, 0, 60)         _GUICtrlListView_SetColumnWidth($hListView, 1, 60)         _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)         For $k = 1 To 4             _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)         Next     Next Next $hEdit = GUICtrlCreateEdit("", 10, 410, 580, 80) ; Create dummy control for the accelerator to action $hAccel_Enter = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Set accelerator for Enter to use if editing Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop         Case $hAccel_Enter ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             _End_SubItemEdit() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $hListView = $aLV_Handles[$fDblClk]         $iListView_ID = $fDblClk         $aHit = _GUICtrlListView_SubItemHitTest($hListView)         If $aHit[0] <> -1 Then             _Start_ItemEdit()         EndIf         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & @CRLF & "has been altered" & @CRLF)     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     #forceref $hWnd, $iMsg, $wParam     Local $hWndFrom, $iCode, $tNMHDR     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iCode = DllStructGetData($tNMHDR, "Code")     For $i = 1 To 6         If $aLV_Handles[$i] = $hWndFrom Then             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = $i             EndSwitch             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)     #forceref $hWnd, $Msg, $wParam     Local $iCode = BitShift($wParam, 16)     Switch $lParam         Case $hEdit             Switch $iCode                 Case $EN_KILLFOCUS                     _End_SubItemEdit()             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc   ;==>WM_COMMAND Func _Start_ItemEdit()     $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])     Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])     Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])     Local $aPos = WinGetPos($hListView)     Local $tPoint = DllStructCreate("int X;int Y")     DllStructSetData($tPoint, "X", $aPos[0])     DllStructSetData($tPoint, "Y", $aPos[1])     _WinAPI_ScreenToClient($hGUI, $tPoint)     Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]     Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]     $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))     _GUICtrlEdit_SetSel($hEdit, 0, -1)     _WinAPI_SetFocus($hEdit)     $hDC = _WinAPI_GetWindowDC($hEdit)     $hBrush = _WinAPI_CreateSolidBrush(0)     Local $stRect = DllStructCreate("int;int;int;int")     DllStructSetData($stRect, 1, $iLen + 10)     DllStructSetData($stRect, 2, 0)     DllStructSetData($stRect, 3, 0)     DllStructSetData($stRect, 4, 17)     DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)     ; Set acclerator key     GUISetAccelerators($aAccelKeys) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc Func _End_SubItemEdit()     Local $sText = _GUICtrlEdit_GetText($hEdit)     If $sText <> $sItemText Then         _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])         $fEdited = True     EndIf     _WinAPI_DeleteObject($hBrush)     _WinAPI_ReleaseDC($hEdit, $hDC)     _WinAPI_DestroyWindow($hEdit)     $hListView = 0     ; Clear accelerator key     GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc

The edit control is just there so that you can see that the ENTER key works normally when you are not editing the ListView. :(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#12 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 15 November 2010 - 01:41 PM

Thanks alot!

if i wanne change the data of the items in my list.

during every 1 minit for example

what is the best way to do this?

yucatan,

I would use an Accelerator key - these are like HotKeys but only work within your app rather than on all running processes. You could code it like this - look for the <<<<<<<<<<<<<<< lines: :graduated:

AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include <GuiEdit.au3> Global $fDblClk = 0, $fEdited = False Global $hListView = 0, $hEdit, $hDC, $hBrush, $aHit Global $iListView_ID, $sItemText Global $aLV_Handles[7] Global $hGUI = GUICreate("Test", 600, 500) For $i = 1 To 3     For $j = 0 To 1         $hListView = _GUICtrlListView_Create($hGUI, "Col 1", 2 + (200 * ($i - 1)), 2 + (200 * $j), 196, 196, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)         _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)         $aLV_Handles[$i + ($j * 3)] = $hListView         _GUICtrlListView_AddColumn($hListView, "Col 2")         _GUICtrlListView_AddColumn($hListView, "Col 3")         ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))         _GUICtrlListView_SetColumnWidth($hListView, 0, 60)         _GUICtrlListView_SetColumnWidth($hListView, 1, 60)         _GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)         For $k = 1 To 4             _GUICtrlListView_AddItem($hListView, "Item " & $i + ($j * 3) & $k)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(64 + $k), 1)             _GUICtrlListView_AddSubItem($hListView, $k - 1, "Sub " & $i + ($j * 3) & Chr(77 + $k), 2)         Next     Next Next $hEdit = GUICtrlCreateEdit("", 10, 410, 580, 80) ; Create dummy control for the accelerator to action $hAccel_Enter = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Set accelerator for Enter to use if editing Dim $aAccelKeys[1][2]=[["{ENTER}", $hAccel_Enter]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ExitLoop         Case $hAccel_Enter ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             _End_SubItemEdit() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<     EndSwitch     ; If an item was double clicked     If $fDblClk Then         $hListView = $aLV_Handles[$fDblClk]         $iListView_ID = $fDblClk         $aHit = _GUICtrlListView_SubItemHitTest($hListView)         If $aHit[0] <> -1 Then             _Start_ItemEdit()         EndIf         $fDblClk = 0     EndIf     If $fEdited Then         $fEdited = False         ConsoleWrite("ListView " & $iListView_ID & " : Row " & $aHit[0] + 1 & @CRLF & "has been altered" & @CRLF)     EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     #forceref $hWnd, $iMsg, $wParam     Local $hWndFrom, $iCode, $tNMHDR     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iCode = DllStructGetData($tNMHDR, "Code")     For $i = 1 To 6         If $aLV_Handles[$i] = $hWndFrom Then             Switch $iCode                 Case $NM_DBLCLK                     $fDblClk = $i             EndSwitch             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)     #forceref $hWnd, $Msg, $wParam     Local $iCode = BitShift($wParam, 16)     Switch $lParam         Case $hEdit             Switch $iCode                 Case $EN_KILLFOCUS                     _End_SubItemEdit()             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc   ;==>WM_COMMAND Func _Start_ItemEdit()     $sItemText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1])     Local $iLen = _GUICtrlListView_GetColumnWidth($hListView, $aHit[1])     Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $aHit[0], $aHit[1])     Local $aPos = WinGetPos($hListView)     Local $tPoint = DllStructCreate("int X;int Y")     DllStructSetData($tPoint, "X", $aPos[0])     DllStructSetData($tPoint, "Y", $aPos[1])     _WinAPI_ScreenToClient($hGUI, $tPoint)     Local $iEdit_X = DllStructGetData($tPoint, "X") + $aRect[0]     Local $iEdit_Y = DllStructGetData($tPoint, "Y") + $aRect[1]     $hEdit = _GUICtrlEdit_Create($hGUI, $sItemText, $iEdit_X + 6, $iEdit_Y, $iLen - 7, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))     _GUICtrlEdit_SetSel($hEdit, 0, -1)     _WinAPI_SetFocus($hEdit)     $hDC = _WinAPI_GetWindowDC($hEdit)     $hBrush = _WinAPI_CreateSolidBrush(0)     Local $stRect = DllStructCreate("int;int;int;int")     DllStructSetData($stRect, 1, $iLen + 10)     DllStructSetData($stRect, 2, 0)     DllStructSetData($stRect, 3, 0)     DllStructSetData($stRect, 4, 17)     DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)     ; Set acclerator key     GUISetAccelerators($aAccelKeys) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc Func _End_SubItemEdit()     Local $sText = _GUICtrlEdit_GetText($hEdit)     If $sText <> $sItemText Then         _GUICtrlListView_SetItemText($hListView, $aHit[0], $sText, $aHit[1])         $fEdited = True     EndIf     _WinAPI_DeleteObject($hBrush)     _WinAPI_ReleaseDC($hEdit, $hDC)     _WinAPI_DestroyWindow($hEdit)     $hListView = 0     ; Clear accelerator key     GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc

The edit control is just there so that you can see that the ENTER key works normally when you are not editing the ListView. :(

M23



#13 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 15 November 2010 - 01:56 PM

yucatan,

How are you getting the data in the first place when you create the ListViews? For example, are you reading from an array? :graduated:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#14 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 15 November 2010 - 02:06 PM

yucatan,

How are you getting the data in the first place when you create the ListViews? For example, are you reading from an array? :graduated:

M23

guictrlsetdata i think.

#15 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 15 November 2010 - 02:14 PM

yucatan,

guictrlsetdata i think

Well, you think wrongly! _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem are used to populate UDF-created ListViews. :(

But the data we use in these commands must come from somewhere. You talk of updating the data in the lists, from where do you get these updates? In what form is the new data delivered? :graduated:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#16 yucatan

yucatan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 587 posts

Posted 15 November 2010 - 02:28 PM

from a mysql database. but its coming in a array.

yucatan,


Well, you think wrongly! _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem are used to populate UDF-created ListViews. :(

But the data we use in these commands must come from somewhere. You talk of updating the data in the lists, from where do you get these updates? In what form is the new data delivered? :graduated:

M23



#17 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 15 November 2010 - 02:46 PM

yucatan,

Then you need a TimerInit/TimerDiff loop or an Adlib function to read the new data from the array into the ListViews at the appropriate interval. :graduated:

I would strongly suggest that you use the _GUICtrlListView_DeleteAllItems command to remove all the existing items in the ListViews before you reload then with the new values. :(

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#18 guinness

guinness

    guinness

  • MVPs
  • 11,067 posts

Posted 15 November 2010 - 05:03 PM

Even though it's kind of off topic, Thanks ever so much for posting that Edit All Items in a ListView with the Enter Key, this is going in my useful Functions/Solutions (along with your Toast UDF & StringSize UDF! :graduated:)

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#19 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,762 posts

Posted 15 November 2010 - 05:09 PM

guinness,

Glad you liked it! :graduated:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
RecFileListToArray- An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items

#20 guinness

guinness

    guinness

  • MVPs
  • 11,067 posts

Posted 15 November 2010 - 05:34 PM

If I don't see a post (with an example) from you within 24 hours I start to get worried :( You have directly/indirectly helped me understand a lot about AutoIt with your wiki/forum entries. Sometimes I think people take advantage of your kind nature and a thank you once in a while is just as good as an apple a day! :graduated:

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users