shEiD Posted July 2, 2010 Share Posted July 2, 2010 For some reason $LVS_EDITLABELS listview style doesn't work. Is this a bug? It lets to edit the text, but then reverts back. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> GUICreate("test", 200, 200) $Listview = GUICtrlCreateListView("column", 5, 5, 190, 190, $LVS_EDITLABELS) GUICtrlCreateListViewItem("text1", $Listview) GUICtrlCreateListViewItem("text2", $Listview) GUICtrlCreateListViewItem("text3", $Listview) GUISetState(@SW_SHOW) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE OS: Win7 AutoIt: 3.3.6.1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 2, 2010 Moderators Share Posted July 2, 2010 shEiD,You need to do a bit more than just adding the $LVS_EDITLABELS style to the ListView! This code works for either the built-in or UDF ListViews - double-click on an item to edit it:expandcollapse popup#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 EndFuncNotice that as we are using blocking functions (needing user input) when we edit the items, we cannot put the code inside the message handler. if we were to do so, the system would rapidly become unstable. Look at the tutorial on GUIRegisterMsg in the Wiki for more information as to why. I hope this helps. M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
shEiD Posted July 2, 2010 Author Share Posted July 2, 2010 Thank You, Melba23. Wow, kinda complicated I'll probably try to work out some other way, without using listview editing. But thanks again, nonetheless. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 2, 2010 Moderators Share Posted July 2, 2010 shEid,kinda complicatedNot really, it is a simple message handler. All you need to do is copy the handler function and the GUIRegisterMsg line into your script! Try reading the tutorial on GUIRegisterMsg in the Wiki and see if makes it a bit clearer. M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
gobsor Posted August 13, 2010 Share Posted August 13, 2010 Very helpful, thanks! Just one thing, I tried to edit another column's field changing your example code slightly: If $fDblClk Then $fDblClk = False If Not IsHWnd($tview) Then $tview = GUICtrlGetHandle($tview) $iSelected = _GUICtrlListView_GetSelectedIndices($tview) $cSelected = _GUICtrlListView_GetSelectedColumn($tview) MsgBox(0, "", $iSelected&" - "&$cSelected) If $iSelected <> "" Then _GUICtrlListView_EDITLabel($tview, $iSelected) EndIf $cSelected always returns -1 (failure) - Any idea how i can make all columns' fields editable? regards Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 It would be cool if someone would find a way ! I tried some stuff but i can't get it to work too. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2010 Moderators Share Posted August 30, 2010 Jayson, This is my first attempt to make all fields editable - I am sure it could be improved, but that will be for another day: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <Misc.au3> ; We use ESC to exit the temporary edit Opt("GUICloseOnESC", 0) ; Set flag to indicate double click in ListView Global $fDblClk = False ; Declare global variables Global $aLV_Click_Info, $hTmp_Edit = 0 ; Open DLL for _IsPressed $dll = DllOpen("user32.dll") ; Create GUI $hGUI = GUICreate("Test", 400, 250) $hListView = _GUICtrlListView_Create($hGUI, "Col 0|Col 1|Col 2", 10, 10, 242, 200) _GUICtrlListView_AddItem($hListView, "Item 00",0) _GUICtrlListView_AddSubItem($hListView, 0, "Item 01", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Item 02", 2) _GUICtrlListView_AddItem($hListView, "Item 10",1) _GUICtrlListView_AddItem($hListView, "Item 20",2) _GUICtrlListView_AddItem($hListView, "Item 30",3) GUISetState() ; Look for double clicks GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) Exit EndSwitch ; If a temporary edit exists If $hTmp_Edit <> 0 Then ; If ENTER pressed If _IsPressed("0D", $dll) Then ; Set label to edit content $sText = GUICtrlRead($hTmp_Edit) _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1]) ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf ; If ESC pressed If _IsPressed("1B", $dll) Then ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf EndIf ; If an item was double clicked If $fDblClk Then $fDblClk = False ; Delete any existing temporary edits GUICtrlDelete($hTmp_Edit) ;$hTmp_Edit = 0 ; Read current text of clicked label $sTmp_Text = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Get label position Switch $aLV_Click_Info[1] Case 0 ; On Item $aLV_Rect_Info = _GUICtrlListView_GetItemRect($hListView, $aLV_Click_Info[0], 2) Case Else ; On SubItem $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1]) EndSwitch ; Create temporary edit $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 10, $aLV_Rect_Info[1] + 10, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) GUICtrlSetState($hTmp_Edit, $GUI_FOCUS) EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndIf Return $GUI_RUNDEFMSG EndFunc Double click on an item to edit the text. ENTER sets the text, ESC abandons any changes. Any use? M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 (edited) Thank you for your reply Melba but I am having a little issue right now. I tried to incorporate your script into mine but i'm not sure why it doesn't work Here's the code : expandcollapse popup;#include <_EIPListView.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> Opt("GUICloseOnESC", 0) Global $fDblClk = False Global $aLV_Click_Info, $hTmp_Edit = 0 $dll = DllOpen("user32.dll") Global $Database = "Database.ini", $LireFichier = IniReadSection($Database, "Info") $GUI = GUICreate("Bottin téléphonique personnel", 410, 530) $NVT = GUICtrlCreateListView("", 5, 5, 400, 360) _GUICtrlListView_SetExtendedListViewStyle($NVT, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Ville", 140, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Téléphone", 99, 2) GUICtrlCreateLabel("Ville :", 5, 375, 28, 20) GUICtrlCreateLabel("Nom :", 5, 398, 28, 20) GUICtrlCreateLabel("Numero de téléphone :", 160, 375, 115, 20) $Ville = GUICtrlCreateInput("", 35, 372, 120, 20) $Nom = GUICtrlCreateInput("", 35, 395, 120, 20) $Telephone = GUICtrlCreateInput("", 160, 395, 120, 20) $Ajouter = GUICtrlCreateButton("Ajouter", 30, 445, 80, 25) $Supprimer = GUICtrlCreateButton("Supprimer", 125, 445, 80, 25) $Effacer = GUICtrlCreateButton("Effacer", 220, 445, 80, 25) $Sauvegarder = GUICtrlCreateButton("Sauvegarder", 325, 365, 80, 25) $Annuler = GUICtrlCreateButton("Annuler", 325, 390, 80, 25) If $LireFichier <> 1 Then For $i = 1 To $LireFichier[0][0] $LisVille = $LireFichier[$i][0] $NomTele = StringSplit($LireFichier[$i][1], "|") $LisNom = $NomTele[1] $LisTelephone = $NomTele[2] GUICtrlCreateListViewItem($LisVille & "|" & $LisNom & "|" & $LisTelephone, $NVT) Next EndIf _GUICtrlListView_RegisterSortCallBack($NVT) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 ; If a temporary edit exists If $hTmp_Edit <> 0 Then ; If ENTER pressed If _IsPressed("0D", $dll) Then ; Set label to edit content $sText = GUICtrlRead($hTmp_Edit) _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1]) ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf ; If ESC pressed If _IsPressed("1B", $dll) Then ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf EndIf ; If an item was double clicked If $fDblClk Then $fDblClk = False ; Delete any existing temporary edits GUICtrlDelete($hTmp_Edit) ;$hTmp_Edit = 0 ; Read current text of clicked label $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Get label position Switch $aLV_Click_Info[1] Case 0 ; On Item $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2) Case Else ; On SubItem $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) EndSwitch ; Create temporary edit $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 10, $aLV_Rect_Info[1] + 10, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) GUICtrlSetState($hTmp_Edit, $GUI_FOCUS) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) ExitLoop Case $Ajouter AjouterInfo() Case $Supprimer _GUICtrlListView_DeleteItemsSelected($NVT) Case $Effacer _GUICtrlListView_DeleteAllItems($NVT) Case $Sauvegarder SauveTout() Case $Annuler ExitLoop Case $NVT _GUICtrlListView_SortItems($NVT, GUICtrlGetState($NVT)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($NVT) Func AjouterInfo() $LisVille = GUICtrlRead($Ville) $LisNom = GUICtrlRead($Nom) $LisTelephone = GUICtrlRead($Telephone) $RegardeVille = _GUICtrlListView_FindText($NVT, $LisVille) $RegardeNom = _GUICtrlListView_FindInText($NVT, $LisNom) If $LisVille = "" Then MsgBox(64, "Erreur !", "Désolé, vous avez oubliez d'inscrire une ville !") Else If $LisNom = "" Then MsgBox(48, "Erreur !", "Désolé, vous avez oublié d'inscrire un nom !") Else If StringLen($LisTelephone) > 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop long !") Else If StringLen($LisTelephone) < 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop court !") Else GUICtrlCreateListViewItem($LisVille & "|" & $LisNom & "|" & $LisTelephone, $NVT) GUICtrlSetData($Ville, "") GUICtrlSetData($Nom, "") GUICtrlSetData($Telephone, "") EndIf EndIf EndIf EndIf EndFunc Func SauveTout() If FileExists($Database) Then FileDelete($Database) EndIf For $i = 0 To _GUICtrlListView_GetItemCount($NVT) - 1 $LisVille = _GUICtrlListView_GetItemText($NVT, $i, 0) $LisNom = _GUICtrlListView_GetItemText($NVT, $i, 1) $LisTelephone = _GUICtrlListView_GetItemText($NVT, $i, 2) IniWrite($Database, "Info", $LisVille, $LisNom & "|" & $LisTelephone) Next EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $NVT And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndIf Return $GUI_RUNDEFMSG EndFunc And the Ini file (Database.ini) [Info] JJJJ JJJJJ=CITYYYYYY|1-450-555-5555 RRRR RRRR=TESTT|1-450-775-5555 Edited August 30, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2010 Moderators Share Posted August 30, 2010 Jayson,It only works with the UDF created ListView - like this (look for the <<<<<<<<<<<< lines): expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> Opt("GUICloseOnESC", 0) Global $fDblClk = False Global $aLV_Click_Info, $hTmp_Edit = 0 $dll = DllOpen("user32.dll") Global $Database = "Database.ini", $LireFichier = IniReadSection($Database, "Info") $GUI = GUICreate("Bottin téléphonique personnel", 410, 530) $NVT = _GUICtrlListView_Create($GUI, "", 5, 5, 400, 360); <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_SetExtendedListViewStyle($NVT, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Ville", 140, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Téléphone", 99, 2) GUICtrlCreateLabel("Ville :", 5, 375, 28, 20) GUICtrlCreateLabel("Nom :", 5, 398, 28, 20) GUICtrlCreateLabel("Numero de téléphone :", 160, 375, 115, 20) $Ville = GUICtrlCreateInput("", 35, 372, 120, 20) $Nom = GUICtrlCreateInput("", 35, 395, 120, 20) $Telephone = GUICtrlCreateInput("", 160, 395, 120, 20) $Ajouter = GUICtrlCreateButton("Ajouter", 30, 445, 80, 25) $Supprimer = GUICtrlCreateButton("Supprimer", 125, 445, 80, 25) $Effacer = GUICtrlCreateButton("Effacer", 220, 445, 80, 25) $Sauvegarder = GUICtrlCreateButton("Sauvegarder", 325, 365, 80, 25) $Annuler = GUICtrlCreateButton("Annuler", 325, 390, 80, 25) If $LireFichier <> 1 Then For $i = 1 To $LireFichier[0][0] $LisVille = $LireFichier[$i][0] $NomTele = StringSplit($LireFichier[$i][1], "|") $LisNom = $NomTele[1] $LisTelephone = $NomTele[2] _GUICtrlListView_AddItem($NVT, $LisVille,$i - 1); <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisNom, 1); <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisTelephone, 2); <<<<<<<<<<<<<<<<<<<<<<<<<<< Next EndIf _GUICtrlListView_RegisterSortCallBack($NVT) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 ; If a temporary edit exists If $hTmp_Edit <> 0 Then ; If ENTER pressed If _IsPressed("0D", $dll) Then ; Set label to edit content $sText = GUICtrlRead($hTmp_Edit) _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1]) ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf ; If ESC pressed If _IsPressed("1B", $dll) Then ; Delete temporary edit GUICtrlDelete($hTmp_Edit) $hTmp_Edit = 0 EndIf EndIf ; If an item was double clicked If $fDblClk Then $fDblClk = False ; Delete any existing temporary edits GUICtrlDelete($hTmp_Edit) ;$hTmp_Edit = 0 ; Read current text of clicked label $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Get label position Switch $aLV_Click_Info[1] Case 0 ; On Item $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2) Case Else ; On SubItem $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) EndSwitch ; Create temporary edit $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 5, $aLV_Rect_Info[1] + 5, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) GUICtrlSetState($hTmp_Edit, $GUI_FOCUS) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) ExitLoop Case $Ajouter AjouterInfo() Case $Supprimer _GUICtrlListView_DeleteItemsSelected($NVT) Case $Effacer _GUICtrlListView_DeleteAllItems($NVT) Case $Sauvegarder SauveTout() Case $Annuler ExitLoop Case $NVT _GUICtrlListView_SortItems($NVT, GUICtrlGetState($NVT)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($NVT) Func AjouterInfo() $LisVille = GUICtrlRead($Ville) $LisNom = GUICtrlRead($Nom) $LisTelephone = GUICtrlRead($Telephone) $RegardeVille = _GUICtrlListView_FindText($NVT, $LisVille) $RegardeNom = _GUICtrlListView_FindInText($NVT, $LisNom) If $LisVille = "" Then MsgBox(64, "Erreur !", "Désolé, vous avez oubliez d'inscrire une ville !") Else If $LisNom = "" Then MsgBox(48, "Erreur !", "Désolé, vous avez oublié d'inscrire un nom !") Else If StringLen($LisTelephone) > 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop long !") Else If StringLen($LisTelephone) < 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop court !") Else GUICtrlCreateListViewItem($LisVille & "|" & $LisNom & "|" & $LisTelephone, $NVT) GUICtrlSetData($Ville, "") GUICtrlSetData($Nom, "") GUICtrlSetData($Telephone, "") EndIf EndIf EndIf EndIf EndFunc Func SauveTout() If FileExists($Database) Then FileDelete($Database) EndIf For $i = 0 To _GUICtrlListView_GetItemCount($NVT) - 1 $LisVille = _GUICtrlListView_GetItemText($NVT, $i, 0) $LisNom = _GUICtrlListView_GetItemText($NVT, $i, 1) $LisTelephone = _GUICtrlListView_GetItemText($NVT, $i, 2) IniWrite($Database, "Info", $LisVille, $LisNom & "|" & $LisTelephone) Next EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $NVT And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndIf Return $GUI_RUNDEFMSG EndFuncIt works fine for me now. M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 (edited) For some reason it doesn't load anything here Edited August 30, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2010 Moderators Share Posted August 30, 2010 Jayson, Sure the ini file exists? I used the one you posted and it loads without any problem. What errorchecking have you tried? M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 I tried with _ArrayDisplay to see if the file was loading and i had nothing as result until I add the data manually. and i got another problem. If i'm addind the data manually and i click on Sauvegarder it save but not on the ini file. If i open it back the data that I entered is still there even if it's not inside the ini Btw i'm using W7 64bits Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2010 Moderators Share Posted August 30, 2010 (edited) Jayson,I was only looking to integrate the "label edit" code into your script. I did not change at anything else in the script.Did the ini file load with the code you posted above? If so, there is no reason for it not too now. I will look into your other problem now. M23Edit:Change your AjouterInfo function to this - I missed it last time round :Func AjouterInfo() $LisVille = GUICtrlRead($Ville) $LisNom = GUICtrlRead($Nom) $LisTelephone = GUICtrlRead($Telephone) $RegardeVille = _GUICtrlListView_FindText($NVT, $LisVille) $RegardeNom = _GUICtrlListView_FindInText($NVT, $LisNom) If $LisVille = "" Then MsgBox(64, "Erreur !", "Désolé, vous avez oubliez d'inscrire une ville !") Else If $LisNom = "" Then MsgBox(48, "Erreur !", "Désolé, vous avez oublié d'inscrire un nom !") Else If StringLen($LisTelephone) > 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop long !") Else If StringLen($LisTelephone) < 14 Then MsgBox(48, "Erreur !", "Désolé, le numéro de téléphone que vous avez entrer est trop court !") Else $iIndex = _GUICtrlListView_GetItemCount($NVT) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<< If $iIndex = -1 Then $iIndex = 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddItem($NVT, $LisVille, $i) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $i, $LisNom, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $i, $LisTelephone, 2) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetData($Ville, "") GUICtrlSetData($Nom, "") GUICtrlSetData($Telephone, "") EndIf EndIf EndIf EndIf EndFunc ;==>AjouterInfoWhat luck in getting the ini file to load? M23 Edited August 30, 2010 by Melba23 shotiko 1  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 (edited) Melba,Sorry, it was my mistake . I had my script in a folder but not the new one that you showed. It was on the deskop that why it was not loading the same ini file .Now it load the ini file perfectly !! The modification of AjouterInfo works but it don't show the subitem when i'm adding data. It only works if the first data in the ini file is populated correctly and then the second data is ok. If the ini file doesn't exist/or emtpy the program crash.Here's the picture Edited August 30, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2010 Moderators Share Posted August 30, 2010 Jayson,Try this in the AjouterInfo function - I think I have the index correct now: Else $iIndex = _GUICtrlListView_GetItemCount($NVT) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< If $iIndex = -1 Then $iIndex = 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddItem($NVT, $LisVille, $iIndex) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $iIndex, $LisNom, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< _GUICtrlListView_AddSubItem($NVT, $iIndex, $LisTelephone, 2) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetData($Ville, "") GUICtrlSetData($Nom, "") GUICtrlSetData($Telephone, "") EndIf EndIfM23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Jayson Posted August 30, 2010 Share Posted August 30, 2010 (edited) I ended up with the same idea as you to fix it Everything works flawless because of you Thank you very much Melba ! Edited August 30, 2010 by Jayson Link to comment Share on other sites More sharing options...
engjcowi Posted November 19, 2010 Share Posted November 19, 2010 Hi guys ive been using this example to learn. In this example if i had 20 records in the database and i when i opened the program i wanted to list them in either name (alphabetical) or ville how would i go about it? also if i added a date column how would i go about getting it to sort by date? thanks jamie Drunken Frat-Boy Monkey Garbage Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2010 Moderators Share Posted November 19, 2010 engjcowi,You can sort the items in the first column automatically by using the $LVS_SORTASCENDING/$LVS_SORTDESCENDING styles. Once the ListView is displayed you can sort any column by clicking on the header (clicking again reverses the order). This simple script based on the Help file example shows you how to code it: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $hGUI = GUICreate("ListView SimpleSort", 400, 300) Global $hListView = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268, $LVS_SORTASCENDING, $LVS_EX_FULLROWSELECT) Global $hWndListView = GUICtrlGetHandle($hListView) GUICtrlCreateListViewItem("line4|5|more_a", $hListView) GUICtrlCreateListViewItem("line5|4.50 |more_c", $hListView) GUICtrlCreateListViewItem("line5|4.0 |more_c", $hListView) GUICtrlCreateListViewItem("line3|23|more_e", $hListView) GUICtrlCreateListViewItem("line2|0.34560 |more_d", $hListView) GUICtrlCreateListViewItem("line1|1.0 |more_b", $hListView) GUICtrlCreateListViewItem("line1|0.1 |more_b", $hListView) GUICtrlCreateListViewItem("line1|10|more_b", $hListView) _GUICtrlListView_SetColumnWidth($hListView, 0, 75) _GUICtrlListView_SetColumnWidth($hListView, 1, 75) _GUICtrlListView_SetColumnWidth($hListView, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] ; Loop until user exits While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ; If the ListView sent the message Case $hWndListView Switch DllStructGetData($tNMHDR, "Code") ; If a column was clicked Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYIf you want to have the elements in another column ready sorted as the ListView displays, then I suggest you load the data into an array, sort the correct dimension in the array and then write the sorted data to the ListView. M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Zedna Posted November 19, 2010 Share Posted November 19, 2010 If you want to have the elements in another column ready sorted as the ListView displays, then I suggest you load the data into an array, sort the correct dimension in the array and then write the sorted data to the ListView. M23There is another way for sorting listview columns (also by column click).Look at GUICtrlRegisterListViewSort() and examples in helpfile Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted November 19, 2010 Share Posted November 19, 2010 (edited) There is another way for sorting listview columns (also by column click). Look at GUICtrlRegisterListViewSort() and examples in helpfile In case of using GUICtrlRegisterListViewSort() there is very simple way for "manual" sorting: Func DoSort() $struct_NMLISTVIEW = DllStructCreate("hwnd;uint;uint;int;int;uint;uint;uint;int;int;int") DllStructSetData($struct_NMLISTVIEW,1,GUICtrlGetHandle($ListView1)) DllStructSetData($struct_NMLISTVIEW,2,$ListView1) DllStructSetData($struct_NMLISTVIEW,3,$LVN_COLUMNCLICK) DllStructSetData($struct_NMLISTVIEW,4,-1) ; item = -1 DllStructSetData($struct_NMLISTVIEW,5,0) ; subitem=0 --> first column _SendMessage($Form1, $WM_NOTIFY, $ListView1, DllStructGetPtr($struct_NMLISTVIEW)) $struct_NMLISTVIEW = 0 EndFunc EDIT: As you can see this function simulates click on column of ListView This function can be parametrized to be more general, I used it this way in my script for sorting by first column only Edited November 19, 2010 by Zedna pixelsearch 1 Resources UDF  ResourcesEx UDF  AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now