Jump to content

I'm not fluent in English, I hope you all understand


 Share

Recommended Posts

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

Link to comment
Share on other sites

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 by Dan_555
deleted the attached picture

Some of my script sourcecode

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

 

FB_IMG_1595250095975.jpg

Link to comment
Share on other sites

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

Untitled.jpg

Link to comment
Share on other sites

You have to be patient.  Here is the code.

#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 by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

  • Moderators
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!

Link to comment
Share on other sites

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
 

Link to comment
Share on other sites

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.

 

#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 by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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