Loc Posted July 20, 2020 Posted July 20, 2020 I found the code when I added it to Listview when it was duplicated, and then I reported an error.If someone kindly helped me with the fix, the amount increased to 2 + 1 = 3 for me: (( Here is the code: #include <Array.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 217, 266, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $Input = GUICtrlCreateInput("", 8, 8, 121, 21) $Button = GUICtrlCreateButton("Add", 136, 6, 75, 25) $List = GUICtrlCreateListView("Values Added", 8, 40, 201, 214, _ BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _ BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 175) GUISetState(@SW_SHOW) Global $aValues[1] GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button Add() EndSwitch WEnd Func Add() $value = GUICtrlRead($Input) If _ArraySearch($aValues, $value) = -1 And $value <> "" Then _ArrayAdd($aValues, $value) GUICtrlCreateListViewItem($value, $List) GUICtrlSetData($Input, "") Else MsgBox(16, "Error", "Value " & $value & " already exists!") EndIf EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then Add() Return "GUI_RUNDEFMSG" EndFunc
Dan_555 Posted July 20, 2020 Posted July 20, 2020 (edited) Sorry, can you tell us more about the error ? There is a listview, with an add button. When a number (or string) is entered and and the button is clicked, it is added to the listview. If the number exists, the number is not added and the user is notified about it. For me, it looks like the code is doing what it should. What is not working with the code ? What are you expecting it to do ? And please, add your code into the Code box. You can do it by clicking on the <> above the editor. Edited July 28, 2020 by Dan_555 deleted the attached picture Some of my script sourcecode
Moderators Melba23 Posted July 20, 2020 Moderators Posted July 20, 2020 Moved to the appropriate forum. Moderation Team 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
Loc Posted July 20, 2020 Author Posted July 20, 2020 1 hour ago, Loc said: Tôi đã tìm thấy mã khi tôi thêm nó vào Listview khi nó bị trùng lặp và sau đó tôi đã báo cáo lỗi. Nếu ai đó vui lòng giúp tôi sửa lỗi, số tiền tăng lên 2 + 1 = 3 cho tôi: (( Đây là mã: #include <Array.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $ hGUI = GUICreate ("Test", 217, 266, -1, -1, BitOR ($ GUI_SS_DEFAULT_GUI, $ WS_MAXIMIZEBOX, $ WS_SIZEBOX, $ WS_THICKFRAME, $ WS_TABSTOP)) $ Input = GUICt , 21) $ Nút = GUICtrlCreateButton ("Thêm", 136, 6, 75, 25) $ List = GUICtrlCreateListView ("Giá trị được thêm", 8, 40, 201, 214, _ BitOR ($ GUI_SS_DEFAULT_LISTVIEW, $ $ WS_VSCROLL), _ BitOR ($ WS_EX_CLIENTEDGE, $ LVS_EX_GRIDLINES, $ LVS_EX_FULLROWSELECT, $ LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg (-1, $ LVM_SETCOLUMNWIDTH, 0, 175) GUISetState (@SW_SHOW) Giá trị toàn cầu $ aValues [1] GUIRegisterMsg ($ WM_COMMAND, "WM_COMMAND") Trong khi 1 $ nMsg = GUIGetMsg () Chuyển trường hợp $ nMsg $ GUI_EVENT_CLOSE Trường hợp thoát $ Nút Thêm () EndSwitch WEnd Func Add () $ value = GUICtrlRead ($ Input) Nếu _ArraySearch ($ aValues, $ value) = -1 Và $ value <> "" Sau đó _ArrayAdd ($ aValues, $ value) GUICtrlCreateListViewItem ($ value, $ danh sách) GUICtrlSetData ( $ Input, "") Khác MsgBox (16, "Lỗi", "Giá trị" & $ value & "đã tồn tại!") End If EndFunc Func WM_COMMAND ($ hWnd, $ iMsg, $ iwParam, $ ilParam) Nếu $ iwParam = 1 Sau đó thêm () Trả về "GUI_RUNDEFMSG" EndFunc
Loc Posted July 20, 2020 Author Posted July 20, 2020 Can someone help me? The address value is taken from the extra Amount taken from the combobox. I want when adding to the listview, Value address is duplicated, can I add the Amount? Here is the source code I need to replace the else instead of using the error message msgbox and use it to increase the amount for me: 3 #include <Array.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 280, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $Input = GUICtrlCreateInput("", 8, 8, 130, 21) $Button = GUICtrlCreateButton("Add", 200, 6, 75, 30) $Combo = GUICtrlCreateCombo("", 8, 30, 130, 21) For $i = 1 to 10 GUICtrlSetData($Combo, $i,1) Next $List = GUICtrlCreateListView("Values Added|Amount", 8, 60, 250, 230, _ BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _ BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUISetState(@SW_SHOW) Global $aValues[1] GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button Add() EndSwitch WEnd Func Add() $tring = GUICtrlRead($Input) $value = GUICtrlRead($Combo) If _ArraySearch($aValues, $tring) = -1 And $tring <> "" Then _ArrayAdd($aValues, $tring) GUICtrlCreateListViewItem($tring & "|" & $value, $List) GUICtrlSetData($Input, "") Else MsgBox(16, "Error", "Notification" & $tring & " already exists!") EndIf EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then Add() Return "GUI_RUNDEFMSG" EndFunc
Moderators JLogan3o13 Posted July 20, 2020 Moderators Posted July 20, 2020 @Loc stick to one thread per topic. Threads merged. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Dan_555 Posted July 20, 2020 Posted July 20, 2020 (edited) You have to be patient. Here is the code. expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $hGUI = GUICreate("Test", 280, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $Input = GUICtrlCreateInput("", 8, 8, 130, 21) $Button = GUICtrlCreateButton("Add", 200, 6, 75, 30) $Combo = GUICtrlCreateCombo("", 8, 30, 130, 21, $CBS_DROPDOWNLIST) For $i = 1 To 10 GUICtrlSetData($Combo, $i, 1) Next $List = GUICtrlCreateListView("Values Added|Amount", 8, 60, 250, 230, _ BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _ BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUISetState(@SW_SHOW) Global $aValues[1][3] $aValues[0][0]=0 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button Add() EndSwitch WEnd Func Add() Local $vr,$am, $ValueCount $value = GUICtrlRead($Input) $am=GUICtrlRead($Combo) $vr = _ArraySearch($aValues, $value, 1) If StringStripWS( $value,8) <> "" Then If $vr = -1 Then $ValueCount=$aValues[0][0]+1 _ArrayAdd($aValues, $value) $aValues[$ValueCount][2]=GUICtrlCreateListViewItem($value & "|" & $am , $List) $aValues[$ValueCount][1]=$am $aValues[0][0]=$ValueCount ;GUICtrlSetData($Input, "") Else CW("Error - Value " & $value & " already exists! :adding " & $am & " to " & $aValues[$vr][1]) $aValues[$vr][1]=$aValues[$vr][1]+$am _GUICtrlListView_BeginUpdate($list) _GUICtrlListView_SetItemText ($List,$vr-1,$aValues[$vr][1],1) _GUICtrlListView_EndUpdate($list) EndIf EndIf EndFunc ;==>Add Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then Add() Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Func CW($txt) ConsoleWrite($txt & @CRLF) EndFunc ;==>CW Edited July 20, 2020 by Dan_555 Some of my script sourcecode
Nine Posted July 20, 2020 Posted July 20, 2020 Do not search if $value = "" as it is useless... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Moderators JLogan3o13 Posted July 20, 2020 Moderators Posted July 20, 2020 53 minutes ago, Loc said: Help me :(( You need to show some patience, this may be the most important thing in the world to you but spamming the forum will not get you help faster. Please wait 24 hours before bumping your thread. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Loc Posted July 21, 2020 Author Posted July 21, 2020 Please help me again. I don't know why I added it to the listview and deleted it next time I couldn't add it again ( #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $hGUI = GUICreate("Sell", 300, 320, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $Input = GUICtrlCreateInput("", 8, 8, 130, 21) $Input2 = GUICtrlCreateInput("", 8, 55, 130, 21) $Button = GUICtrlCreateButton("Add", 200, 6, 75, 30) $Button2 = GUICtrlCreateButton("Delete", 200, 36, 75, 30) $Combo = GUICtrlCreateCombo("", 8, 30, 130, 21, $CBS_DROPDOWNLIST) For $i = 1 To 10 GUICtrlSetData($Combo, $i, 1) Next $List = GUICtrlCreateListView("Values Added|Amount|Money", 8, 90, 290, 230, _ BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _ BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUISetState(@SW_SHOW) Global $aValues[1][3] $aValues[0][0]=0 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button Add() Case $Button2 _GUICtrlListView_DeleteItemsSelected($List) EndSwitch WEnd Func Add() Local $vr,$am, $ValueCount $value = GUICtrlRead($Input) $value2 = GUICtrlRead($Input2) $am=GUICtrlRead($Combo) $vr = _ArraySearch($aValues, $value, 1) If StringStripWS( $value,8) <> "" Then If $vr = -1 Then $ValueCount=$aValues[0][0]+1 _ArrayAdd($aValues, $value) $aValues[$ValueCount][2]=GUICtrlCreateListViewItem($value & "|" & $am & "|" & $value2, $List) $aValues[$ValueCount][1]=$am $aValues[$ValueCount][2]=$value2 $aValues[0][0]=$ValueCount Else CW("Error - Value " & $value & " already exists! :adding " & $am & " to " & $aValues[$vr][1]) $aValues[$vr][1]=$aValues[$vr][1]+$am $aValues[$vr][2]=$aValues[$vr][2]+$value2 _GUICtrlListView_BeginUpdate($list) _GUICtrlListView_SetItemText ($List,$vr-1,$aValues[$vr][1],1) _GUICtrlListView_SetItemText ($List,$vr-1,$aValues[$vr][2],2) _GUICtrlListView_EndUpdate($list) EndIf EndIf EndFunc ;==>Add Func Add11() Local $vr,$am, $ValueCount $value = GUICtrlRead($Input) $value2 = GUICtrlRead($Input2) $am=GUICtrlRead($Combo) $vr = _ArraySearch($aValues, $value, 1) If StringStripWS( $value,8) <> "" Then If $vr = -1 Then $ValueCount=$aValues[0][0]+1 _ArrayAdd($aValues, $value) $aValues[$ValueCount][2]=GUICtrlCreateListViewItem($value & "|" & $am & "|" & $value2, $List) $aValues[$ValueCount][1]=$am $aValues[$ValueCount][3]=$value2 $aValues[0][0]=$ValueCount ;GUICtrlSetData($Input, "") Else CW("Error - Value " & $value & " already exists! :adding " & $am & " to " & $aValues[$vr][1]) $aValues[$vr][1]=$aValues[$vr][1]+$am _GUICtrlListView_BeginUpdate($list) _GUICtrlListView_SetItemText ($List,$vr-1,$aValues[$vr][1],1) _GUICtrlListView_EndUpdate($list) EndIf EndIf EndFunc ;==>Add Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then Add() Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Func CW($txt) ConsoleWrite($txt & @CRLF) EndFunc ;==>CW
Dan_555 Posted July 21, 2020 Posted July 21, 2020 (edited) Please add your code to the Code Box. ... Because you were using arrays, i have continued to use and expanded it to hold the list item handle of the added entry. Additionally to deleting the Listview item, you have to delete the item from the array. If you want to add more fields into the List view, then take care of the Global $aValues[1][4] and $aValues[$ValueCount][3] = GUICtrlCreateListViewItem($value & "|" & $am & "|" & $value2, $List) ; Save this for later. by increasing the number ( currently [][4] and [][3] ) Atm, the handle is not used (which is stored in $aValues[][3]), but if you want to perform a search on the array in the future, you can access the corresponding listview item by it. expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $hGUI = GUICreate("Sell", 300, 320, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $Input = GUICtrlCreateInput("", 8, 8, 130, 21) $Input2 = GUICtrlCreateInput("", 8, 55, 130, 21) $Button = GUICtrlCreateButton("Add", 200, 6, 75, 30) $Button2 = GUICtrlCreateButton("Delete", 200, 36, 75, 30) $Combo = GUICtrlCreateCombo("", 8, 30, 130, 21, $CBS_DROPDOWNLIST) For $i = 1 To 10 GUICtrlSetData($Combo, $i, 1) Next $List = GUICtrlCreateListView("Values Added|Amount|Money", 8, 90, 290, 230, _ BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _ BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUISetState(@SW_SHOW) Global $aValues[1][4] $aValues[0][0] = 0 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button Add() Case $Button2 ;_GUICtrlListView_DeleteItemsSelected($List) ; do not use this. Local $x For $x = $aValues[0][0] To 0 Step -1 If _GUICtrlListView_GetItemSelected($List, $x) Then CW($x & " selected") _ArrayDelete($aValues, $x + 1) $aValues[0][0] = $aValues[0][0] - 1 _GUICtrlListView_DeleteItem($List,$x) EndIf Next EndSwitch WEnd Func Add() Local $vr, $am, $ValueCount $value = GUICtrlRead($Input) $value2 = GUICtrlRead($Input2) $am = GUICtrlRead($Combo) $vr = _ArraySearch($aValues, $value, 1) ;This adds the name to $aValues[$vr][0] If StringStripWS($value, 8) <> "" Then If $vr = -1 Then $ValueCount = $aValues[0][0] + 1 _ArrayAdd($aValues, $value) $aValues[$ValueCount][3] = GUICtrlCreateListViewItem($value & "|" & $am & "|" & $value2, $List) ; Save this for later. $aValues[$ValueCount][1] = $am $aValues[$ValueCount][2] = $value2 $aValues[0][0] = $ValueCount Else CW("Value " & $value & " already exists! :adding " & $am & " to " & $aValues[$vr][1]) $aValues[$vr][1] = $aValues[$vr][1] + $am $aValues[$vr][2] = $aValues[$vr][2] + $value2 _GUICtrlListView_BeginUpdate($List) _GUICtrlListView_SetItemText($List, $vr - 1, $aValues[$vr][1], 1) _GUICtrlListView_SetItemText($List, $vr - 1, $aValues[$vr][2], 2) _GUICtrlListView_EndUpdate($List) EndIf EndIf EndFunc ;==>Add Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then Add() Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Func CW($txt) ConsoleWrite($txt & @CRLF) EndFunc ;==>CW Edited July 21, 2020 by Dan_555 Some of my script sourcecode
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