Jayson Posted September 1, 2010 Share Posted September 1, 2010 (edited) Hello AUTOIT community !I ran into a problem today. I'm using _GUICtrlListView_Create to show some data and i'm making a right click in the control that show a popup menu.I can't get to work the Ajoute(it won't show the msgbox if nothing selected) and Efface into ListView_RClick() and if i'm using the button Effacer(same action, same code) it works. Edit : The Ajoute workings great but Efface and Effacer Tout aren't. I can erase a line with Efface but it still show the MsgBox error like i havn't selected nothing. For Effacer Tout it show the MsgBox from Efface, that's all happening.Anyone willing to help me ?expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <GuiMenu.au3> Global $fDblClk = False, $Database = "Database.ini", $LireFichier = IniReadSection($Database, "Info") Global $aLV_Click_Info, $hTmp_Edit = 0 $dll = DllOpen("user32.dll") $GUI = GUICreate("Bottin téléphonique personnel", 510, 450) $NVT = _GUICtrlListView_Create($GUI, "", 5, 5, 500, 347) _GUICtrlListView_SetExtendedListViewStyle($NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_BORDERSELECT)) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Adresse", 130, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Ville", 113, 2) _GUICtrlListView_InsertColumn($NVT, 3, "Téléphone", 100, 2) GUICtrlCreateLabel("Ville", 5, 362, 28, 20) GUICtrlCreateLabel("Nom", 5, 385, 28, 20) GUICtrlCreateLabel("Adresse", 160, 362, 57, 20) GUICtrlCreateLabel("Téléphone", 160, 385, 57, 20) $Ville = GUICtrlCreateInput("", 35, 359, 120, 20) $Nom = GUICtrlCreateInput("", 35, 382, 120, 20) $Adresse = GUICtrlCreateInput("", 218, 359, 120, 20) $Telephone = GUICtrlCreateInput("", 218, 382, 120, 20) $Ajouter = GUICtrlCreateButton("Ajouter", 5, 420, 80, 23) $Supprimer = GUICtrlCreateButton("Supprimer", 100, 420, 80, 23) $Effacer = GUICtrlCreateButton("Effacer", 195, 420, 80, 23) $Sauvegarder = GUICtrlCreateButton("Sauvegarder", 425, 355, 80, 23) $Annuler = GUICtrlCreateButton("Annuler", 425, 379, 80, 23) If $LireFichier <> 1 Then For $i = 1 To $LireFichier[0][0] $LisNom = $LireFichier[$i][0] $AdresseVilleTele = StringSplit($LireFichier[$i][1], "|") $LisAdresse = $AdresseVilleTele[1] $LisVille = $AdresseVilleTele[2] $LisTelephone = $AdresseVilleTele[3] _GUICtrlListView_AddItem($NVT, $LisNom,$i - 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisAdresse, 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisVille, 2) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisTelephone, 3) Next EndIf 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 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 DllClose($dll) ExitLoop EndSwitch WEnd Func AjouterInfo() $LisVille = GUICtrlRead($Ville) $LisNom = GUICtrlRead($Nom) $LisTelephone = GUICtrlRead($Telephone) $LisAdresse = GUICtrlRead($Adresse) If $LisVille = "" Then MsgBox(64, "Erreur !", "Désolé, vous avez oublié 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 !" & @CRLF & @CRLF _ & " Veuillez utiliser le format suivant : 1-234-456-7890") 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 !" & @CRLF & @CRLF _ & " Veuillez utiliser le format suivant : 1-234-456-7890") Else If $Adresse = "" Then MsgBox(48, "Erreur !", "Désolé, vous avez oublié d'inscrire une adresse !") Else $iIndex = _GUICtrlListView_GetItemCount($NVT) If $iIndex = -1 Then $iIndex = 0 _GUICtrlListView_AddItem($NVT, $LisNom, $iIndex) _GuiCtrlListView_AddSubItem($NVT, $iIndex, $LisAdresse, 1) _GUICtrlListView_AddSubItem($NVT, $iIndex, $LisVille, 2) _GUICtrlListView_AddSubItem($NVT, $iIndex, $LisTelephone, 3) GUICtrlSetData($Ville, "") GUICtrlSetData($Nom, "") GUICtrlSetData($Telephone, "") GuiCtrlSetData($Adresse, "") EndIf EndIf EndIf EndIf EndIf EndFunc ;==>AjouterInfo Func SauveTout() If FileExists($Database) Then FileDelete($Database) EndIf For $i = 0 To _GUICtrlListView_GetItemCount($NVT) - 1 $LisNom = _GUICtrlListView_GetItemText($NVT, $i, 0) $LisAdresse = _GUICtrlListView_GetItemText($NVT, $i, 1) $LisVille = _GUICtrlListView_GetItemText($NVT, $i, 2) $LisTelephone = _GUICtrlListView_GetItemText($NVT, $i, 3) IniWrite($Database, "Info", $LisNom, $LisAdresse & "|" & $LisVille & "|" & $LisTelephone) Next EndFunc ;==>SauveTout Func ListView_RClick() Local $ajoute = 1000, $supprime, $efface $Menu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($Menu, "Ajouter", $ajoute) _GUICtrlMenu_AddMenuItem($Menu, "Supprimer", $supprime) _GUICtrlMenu_AddMenuItem($Menu, "") _GUICtrlMenu_AddMenuItem($Menu, "Effacer tout", $efface) Switch _GUICtrlMenu_TrackPopupMenu($Menu, $NVT, -1, -1, 1, 1, 2) Case $ajoute $nom1 = InputBox("Nom", "Veuillez inscrire le nom de la personne à ajouter.", "", " M75") $adresse1 = InputBox("Adresse", "Veuillez inscrire l'adresse où la personne demeure.", "", " M75") $ville1 = InputBox("Ville", "Veuillez inscrire la ville où elle vie.", "", " M75") $telephone1 = InputBox("Numéro de téléphone", "Veuillez inscrire le numéro de téléphone de la personne.", "", " M14") $iIndex = _GUICtrlListView_GetItemCount($NVT) If $iIndex = -1 Then $iIndex = 0 _GUICtrlListView_AddItem($NVT, $Nom1, $iIndex) _GuiCtrlListView_AddSubItem($NVT, $iIndex, $Adresse1, 1) _GUICtrlListView_AddSubItem($NVT, $iIndex, $Ville1, 2) _GUICtrlListView_AddSubItem($NVT, $iIndex, $Telephone1, 3) Case $supprime If _GUICtrlListView_DeleteItemsSelected($NVT) = 0 Then MsgBox(48, "Erreur !", "Veuillez sélectionner une ligne avant de supprimer !") Else _GUICtrlListView_DeleteItemsSelected($NVT) EndIf Case $efface _GUICtrlListView_DeleteAllItems($NVT) EndSwitch _GUICtrlMenu_DestroyMenu($Menu) EndFunc ;==>ListView_RClick Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $NVT Switch $iCode Case $NM_RCLICK ListView_RClick() Case $NM_DBLCLK $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited September 1, 2010 by Jayson Link to comment Share on other sites More sharing options...
UEZ Posted September 1, 2010 Share Posted September 1, 2010 It is working for me. I can press the rmb on the GUI without selecting anything and when selecting "Ajouter" I can add data. Also both other functions (Supprimer and Effacer tout) are working! Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Jayson Posted September 1, 2010 Author Share Posted September 1, 2010 (edited) Hmm, that's pretty strange. If I right click 2 times in the listview if show me the MsgBox Error From Case $supprime. Even if I select a row of data and use Supprimer on the right click it gets the item deleted but also show the MsgBox. Same with Effacer it does nothing but show the MsgBox. Edited September 2, 2010 by Jayson Link to comment Share on other sites More sharing options...
Jayson Posted September 2, 2010 Author Share Posted September 2, 2010 I got it to work but i don't know why it's working that way I changed that line Local $ajoute = 1000, $supprime, $effaceTo Local $ajoute = 1, $supprime = 2, $efface = 3 Now, everything works ! Pretty strange... 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