Jump to content

One Combo For Two Listviews


Go to solution Solved by Melba23,

Recommended Posts

I have created two Listviews and one combobox on one form. Here is my code (which has problems) as I am looking to do the following and am only partially successful.

Both ListView will take data from ONE combobox. One Listview uses 3 column, while the second only uses 2 column.  Data in each case is separate and non dependent on both Listviews.

One thing - after I enter data I need to have the data fields reset to blank for the next entry.

Second - using keyboard and mouse.

On the menu line you can see which Listview is checked for using and also making it enabled and shows.

With the List1(3column Listview) it adds items only if I use the mouse. If I use the enter key data goes to the second List2 Listview.

It almost works but I have something wrong or excluded.

Any help would be appreciated, as i am a new user.  I thought my approach was right in using "enabled" as my indicator but really guessing.

Thanks.  If this is in the wrong forum - sorry and let me know.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <MsgBoxConstants.au3>
 #include <GuiListView.au3>
#include <ColorConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=C:\Users\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)
$combo_b = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData(-1, "a|B|C|D|E|F|G")

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21);

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData(-1, "a|L|M|N|Na|O|P")

$List1 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($list1, "Vendor",290)
_GUICtrlListView_AddColumn($list1, "Category", 90)
_GUICtrlListView_AddColumn($list1, "Amount", 160)

$List2 = GUICtrlCreateListview("", 15, 140, 145, 180,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($list2, "Category", 90)
_GUICtrlListView_AddColumn($list2, "Amount", 160)
GUICtrlSetState($List2,$GUI_DISABLE);
GUICtrlSetState($List2,$GUI_HIDE)


$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Label1 = GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$Label2 = GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel(" Amount", 104, 8, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

 Local $idFilemenu = GUICtrlCreateMenu("&File") ;added August 3,2014
 Local $idRunmenu = GUICtrlCreateMenu("&Run") ;added August 3,2014
 Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
 Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu);added August 3,2014




GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $fComboSelected = False

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)


Global $tInfo, $fComboActive = False
Global $fComboActive2 = False

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)

$hEdit = DllStructGetData($tInfo, "hEdit")
$hlist = DllStructGetData($tInfo, "hList")

$cEnterPressed = GUICtrlCreateDummy()
$cEnterPressed2 = GUICtrlCreateDummy()

GUISetState()

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

global $mycounter = _GUICtrlListView_GetItemCount ( $List1 )

Global $MMM
Global $MM
Global $NNN
Global $NN
Global $AEmoney

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP

            If $fComboActive2 Then
                 GUICtrlSetState ($AEamounts, $GUI_FOCUS)
                EndIf

            If $fComboActive Then

                 $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                 _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)
                 GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney , $List1)
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($hcombo, False)

                _aeReset ()
            EndIf

            _blanker()

        Case     $cEnterPressed
            if GUICtrlSetState($List1,$GUI_enABLE) Then  ;<<<<THREE COLUMN LIST
                $countit = _GUICtrlListView_GetItemCount ( $List1 )
                ;If  _WinAPI_GetFocus() = $hEdit   Then ; old code
                 If _WinAPI_GetFocus() = $hEdit And GUICtrlRead($hcombo) Then   ;suggestion by Melba

                $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)

                GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney, $List1)

                _GUICtrlComboBox_ShowDropDown($hcombo, False)
                 GUICtrlSetState ($hcombo, $GUI_FOCUS)

                If _GUICtrlListView_GetItemCount ( $List1 ) > $countit and $hcombo <> ""  Then
                _aeReset ()
                EndIf
                EndIf
            EndIf
;below is the code for the second listview which has 2 columns
            if GUICtrlSetState($List2,$GUI_enABLE) Then  ;<<< TWO COLUMN LIST
                $countit = _GUICtrlListView_GetItemCount ( $List2 )
                $MM =_GUICtrlComboBox_GetCurSel($combo_b)
                _GUICtrlComboBox_GetLBText($combo_b, $MM, $NN)
                GUICtrlCreateListViewItem(GUICtrlRead($combo_b)&"|"& $AEmoney, $List2)
            EndIf
                If _GUICtrlListView_GetItemCount ( $List2 ) > $countit and $combo_b <> ""  Then
                $NN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
            EndIf
;end of second listview code


        Case $AEamounts

            $AEmoney = GUICtrlRead ( $AEamounts )
            if ($AEmoney/$AEmoney) = 1 And _IsPressed("0D") Then  ; checking for number entry
                GUICtrlSetState ($hcombo, $GUI_FOCUS)

            EndIf

            if ($AEmoney/$AEmoney) <> 1 Then
                MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                _aeReset ()
            EndIf


        Case $Button12

        Case $Button13

                Global $zzzz =_GUICtrlListView_GetSelectedIndices ( $List1 )
                DoubleClickFunc()

            Case $idFileitem
                _set()
            GUICtrlSetState($idLog, $GUI_unCHECKED)
            GUICtrlSetState ($combo_b, $GUI_FOCUS)

    Case $idLog

        GUICtrlSetState($idFileitem, $GUI_unCHECKED)
        GUICtrlSetState($idLog, $GUI_CHECKED)
        GUICtrlSetState($List1,$GUI_enABLE);
        GUICtrlSetState($List1,$GUI_show)
        GUICtrlSetState($List2,$GUI_DISABLE);
        GUICtrlSetState($List2,$GUI_HIDE)
            GUICtrlSetState($hcombo,$GUI_enABLE); hide combo
            GUICtrlSetState($hcombo,$GUI_show)
    EndSwitch

    If _GUICtrlComboBox_GetDroppedState($hcombo) = True Then
        $fComboActive = True
    EndIf

    If _GUICtrlComboBox_GetDroppedState($combo_b) = True Then
        $fComboActive2 = True
    EndIf


WEnd

Func _Edit_Changed($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo) ; <<<<<<<<<<<<<<<<<<<<<
                Case $combo_b
                    _Edit_Changed($combo_b) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


Func _Blanker() ; trying to catch blank field
global $blankcount
$blankcount = _GUICtrlListView_GetItemCount ( $List1 )
for $i = (($blankcount) -1) to 0 step -1
if (_GUICtrlListView_GetItemText ( $List1, $i ))  = "" then
_GUICtrlListView_DeleteItem (  $List1, $i )
EndIf
Next
EndFunc



Func DoubleClickFunc()   ; for the delete button
    Global $DoubleClicked   = False
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    local $msgText = GUICtrlRead(GUICtrlRead($List1))
    local $msgText2 = StringTrimRight ( $msgText, 3 )
    local $msgCheck = MsgBox(4, "OK to : ", "Delete Entry:  " & $msgText2)
    If $msgCheck = 6 then
    _GUICtrlListView_DeleteItemsSelected ( $List1 )

    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $List1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

 Func _aeReset () ; for resetting all fields First Listview to blank in anticipation of the next entry
                $NNN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
            EndFunc

Func _set() ;Run  Setup
            GUICtrlSetState($idLog, $GUI_unCHECKED)
            GUICtrlSetState($List2,$GUI_enABLE);
            GUICtrlSetState($List2,$GUI_show)
            GUICtrlSetState($hcombo,$GUI_DISABLE); hide combo
            GUICtrlSetState($hcombo,$GUI_HIDE)
            GUICtrlSetState($List1,$GUI_DISABLE); hide combo
            GUICtrlSetState($List1,$GUI_HIDE)


    EndFunc
Link to comment
Share on other sites

  • Moderators

Hobbyist,

I am completely lost as to what you want to do with that script - please remember that we are looking at the code completely cold with no preconceived ideas. Am I right in thinking that the combo in which a selection is made determines the ListView to be used? :huh:

Can you give a series of actions and the results that you expect - indicating where the script does not do what you want. ;)

M23

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

Sure, I also felt it may have not been clear, albeit frustraing.
 
Click Run to choose which Listview (Log or Set).
 
Log - List1(three columns) is the defaulting opened one.
Choose Category(first combo) from drop down and focus moves to Amount (Input Box)
Enter Amount ,hit enter key and focus moves to Vendor (second Combo)
Typing or selecting choice (keyboard or mouse). Completing this action adds data to List1.
Category, Amount and Vendor should all reset to blank for next entry. Nothing should happen in List2 which is disabled and no show.
 
Set- List2(two colums) - Clicking this should
Disable and No show List1 and at the same time Enable and show List2.
Vendor Combo is also disabled and no show.
Category and Amount are used as above BUT for entry only in List2.  Vendor is not selected or used.
Category and Amount should reset to blank after each entry. Nothing should happen in List1 which is disabled and no show.
 
 
So I am trying to use (1) combo box and (1) input box to enter data into two different unrelated Listviews. The second combo box is only used in one Listview.  I thought the process could be driven by whether a GUI was enabled/show or disabled/no show, thus the Category and Amount inputs would go to the appropriate Listview.
 
Thanks so much for any help.
Link to comment
Share on other sites

  • Moderators

Hobbyist,

Much clearer - I will take a look. :)

M23

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

  • Moderators

Hobbyist,

How about this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <ColorConstants.au3>

Global $iActive = 1

$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)

Local $idFilemenu = GUICtrlCreateMenu("&File")
Local $idRunmenu = GUICtrlCreateMenu("&Run")
Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu)

$combo_b = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData($combo_b, "|A|B|C|D|E|F|G")

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21);

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData($hcombo, "|K|L|M|N|O|P|Q")

$List1 = GUICtrlCreateListView("", 192, 72, 470, 260, $LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($List1, "Vendor", 290)
_GUICtrlListView_AddColumn($List1, "Category", 90)
_GUICtrlListView_AddColumn($List1, "Amount", 160)

$List2 = GUICtrlCreateListView("", 15, 140, 145, 180, $LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($List2, "Category", 90)
_GUICtrlListView_AddColumn($List2, "Amount", 160)
GUICtrlSetState($List2, $GUI_HIDE)

$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)

GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlCreateLabel("Amount", 104, 8, 50, 17)
GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)

$cEnterPressed = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idLog
            GUICtrlSetState($List1, $GUI_SHOW)
            GUICtrlSetState($hcombo, $GUI_SHOW)
            GUICtrlSetState($List2, $GUI_HIDE)
            $iActive = 1

        Case $idFileitem
            GUICtrlSetState($List2, $GUI_SHOW)
            GUICtrlSetState($List1, $GUI_HIDE)
            GUICtrlSetState($hcombo, $GUI_HIDE)
            $iActive = 2

        Case $combo_b
            GUICtrlSetState($AEamounts, $GUI_FOCUS)

        Case $cEnterPressed
            If _WinAPI_GetFocus() = GUICtrlGetHandle($AEamounts) Then
                Switch $iActive
                    Case 1
                        GUICtrlSetState($hcombo, $GUI_FOCUS)
                    Case 2
                        GUICtrlCreateListViewItem(GUICtrlRead($combo_b) & "|" & GUICtrlRead($AEamounts), $List2)
                        GUICtrlSetData($combo_b, "|A|B|C|D|E|F|G")
                        GUICtrlSetData($AEamounts, "")
                EndSwitch
            EndIf

        Case $hcombo
            GUICtrlCreateListViewItem(GUICtrlRead($hcombo) & "|" & GUICtrlRead($combo_b) & "|" & GUICtrlRead($AEamounts), $List1)
            GUICtrlSetData($combo_b, "|A|B|C|D|E|F|G")
            GUICtrlSetData($AEamounts, "")
            GUICtrlSetData($hcombo, "|K|L|M|N|O|P|Q")
    EndSwitch

WEnd
It seems to work as you described above - I have removed lot of code so that the logic flow is clear (I hope!). ;)

Now if you want to explain what all the other code was doing, we can add further functionality. :)

M23

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

hey M231

Thanks.

Ok here is what some of my code was doing in addition to what is written above and some in comparison to yours.

On the default startup (List1) my code resets the cursor to the Category combo after making an entry, yours stays at the vendor Combo.

On mine - after receiving the focus, the vendor combo allows arrowing through the possible selection or as you type it will go through the matching of letters (with more items added). You can use the enter key or the mouse, yours is the mouse.

The delete button is for the obvious and is based upon the Listview count. This wasn't a problem.

On your List2 (second Listview), after entering data the cursor resets to Amount - this is not  what I wanted to do.  Needs to reset to Category. Mine responds like yours and it should reset to Category. This was a big struggle as I couldn't figure it out.

My delete button worked as coded, so I didn't bother with that.

The save file button works as well.

I had tried both delete and save button when first coding just the List1 Listview and was pleased with it.

If you could help me get somewhere between your functionality and mine it would be great, regarding the above and then I would like to post my code for the saving routine button cuz it may be able to be shortened - I dunno.

Unless I just missed 'em, I couldn't find any other posts for a like problem to see how it was solved.

Thanks much & let me know what ya think.

Link to comment
Share on other sites

  • Moderators

Hobbyist,

I think I have covered everything in that exhaustive list: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <ColorConstants.au3>
#include <GuiComboBox.au3>

Global $iActive = 1
Global $sCategoryData = "|A|B|C|D|E|F|G"
Global $sVendorData = "|Kaa|Kab|L|M|Naa|Nab|O|P|Q"

$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)

Local $idFilemenu = GUICtrlCreateMenu("&File")
Local $idRunmenu = GUICtrlCreateMenu("&Run")
Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu)

$cCombo_Category = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData($cCombo_Category, $sCategoryData)

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21)
GUICtrlSetState($AEamounts, $GUI_DISABLE)

$cCombo_Vendor = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData($cCombo_Vendor, "|Kaa|Kab|L|M|Naa|Nab|O|P|Q")
Local $tInfo
_GUICtrlComboBox_GetComboBoxInfo($cCombo_Vendor, $tInfo)
$hCombo_Vendor_Edit = DllStructGetData($tInfo, "hEdit")
$hCombo_Vendor = GUICtrlGetHandle($cCombo_Vendor)
GUICtrlSetState($cCombo_Vendor, $GUI_DISABLE)

$List1 = GUICtrlCreateListView("", 192, 72, 470, 260, $LVS_SINGLESEL, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($List1, "Vendor", 290)
_GUICtrlListView_AddColumn($List1, "Category", 90)
_GUICtrlListView_AddColumn($List1, "Amount", 160)

$List2 = GUICtrlCreateListView("", 15, 140, 145, 180, $LVS_SINGLESEL, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($List2, "Category", 90)
_GUICtrlListView_AddColumn($List2, "Amount", 160)
GUICtrlSetState($List2, $GUI_HIDE)

$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)

GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlCreateLabel("Amount", 104, 8, 50, 17)
GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)

$cEnterPressed = GUICtrlCreateDummy()
$cDummy_Vendor = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idLog
            GUICtrlSetState($List1, $GUI_SHOW)
            GUICtrlSetState($cCombo_Vendor, $GUI_SHOW)
            GUICtrlSetState($List2, $GUI_HIDE)
            $iActive = 1

        Case $idFileitem
            GUICtrlSetState($List2, $GUI_SHOW)
            GUICtrlSetState($List1, $GUI_HIDE)
            GUICtrlSetState($cCombo_Vendor, $GUI_HIDE)
            $iActive = 2

        Case $cCombo_Category
            GUICtrlSetState($AEamounts, BitOR($GUI_FOCUS, $GUI_ENABLE))


        Case $cEnterPressed
            Switch _WinAPI_GetFocus()
                Case GUICtrlGetHandle($AEamounts)
                    Switch $iActive
                        Case 1
                            GUICtrlSetState($cCombo_Vendor, BitOR($GUI_FOCUS, $GUI_ENABLE))
                        Case 2
                            GUICtrlCreateListViewItem(GUICtrlRead($cCombo_Category) & "|" & GUICtrlRead($AEamounts), $List2)
                            GUICtrlSetData($cCombo_Category, $sCategoryData)
                            GUICtrlSetData($AEamounts, "")
                            GUICtrlSetState($cCombo_Category, $GUI_FOCUS)
                            GUICtrlSetState($AEamounts, $GUI_DISABLE)
                    EndSwitch
                Case $hCombo_Vendor_Edit
                    GUICtrlSendToDummy($cDummy_Vendor)

            EndSwitch

        Case $cCombo_Vendor, $cDummy_Vendor
            GUICtrlCreateListViewItem(GUICtrlRead($cCombo_Vendor) & "|" & GUICtrlRead($cCombo_Category) & "|" & GUICtrlRead($AEamounts), $List1)
            GUICtrlSetData($cCombo_Category, $sCategoryData)
            GUICtrlSetData($AEamounts, "")
            GUICtrlSetData($cCombo_Vendor, $sVendorData)
            GUICtrlSetState($cCombo_Category, $GUI_FOCUS)
            GUICtrlSetState($AEamounts, $GUI_DISABLE)
            GUICtrlSetState($cCombo_Vendor, $GUI_DISABLE)
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    $hWndFrom = $lParam
    $iCode = BitShift($wParam, 16) ; Hi Word
    If $hWndFrom = $hCombo_Vendor And $iCode = $CBN_EDITCHANGE Then
        _GUICtrlComboBox_AutoComplete($hCombo_Vendor)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
Please ask if you do not understand any of the code - or why I did something different to your original method. :)

M23

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

Hi M23!

I'm back.  

Ok so at your invitation to "ask"........ with the goal of learning two things. Looking at the difference between my code and yours is like the difference between a Cadillac and a Chevy ( a wrecked Chevy)

1. Why you took the approach you did. It seems clean and efficient. Mine not so much.

I also noticed in yours, the arrow up/down keys cause items to be added. Mine allows for scrolling through the edit box and then use the enter key or the mouse. 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <MsgBoxConstants.au3>
 #include <GuiListView.au3>
#include <ColorConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=C:\Users\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)
$combo_b = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData(-1, "a|B|C|D|E|F|G")

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21);

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData(-1, "a|L|M|N|Na|O|P")

$List1 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($list1, "Vendor",290)
_GUICtrlListView_AddColumn($list1, "Category", 90)
_GUICtrlListView_AddColumn($list1, "Amount", 160)

$List2 = GUICtrlCreateListview("", 15, 140, 145, 180,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($list2, "Category", 90)
_GUICtrlListView_AddColumn($list2, "Amount", 160)
GUICtrlSetState($List2,$GUI_DISABLE);
GUICtrlSetState($List2,$GUI_HIDE)


$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Label1 = GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$Label2 = GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel(" Amount", 104, 8, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

 Local $idFilemenu = GUICtrlCreateMenu("&File") ;added August 3,2014
 Local $idRunmenu = GUICtrlCreateMenu("&Run") ;added August 3,2014
 Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
 Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu);added August 3,2014




GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $fComboSelected = False

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)


Global $tInfo, $fComboActive = False
Global $fComboActive2 = False

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)

$hEdit = DllStructGetData($tInfo, "hEdit")
$hlist = DllStructGetData($tInfo, "hList")

$cEnterPressed = GUICtrlCreateDummy()
$cEnterPressed2 = GUICtrlCreateDummy()

GUISetState()

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

global $mycounter = _GUICtrlListView_GetItemCount ( $List1 )

Global $MMM
Global $MM
Global $NNN
Global $NN
Global $AEmoney

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP

            If $fComboActive2 Then
                 GUICtrlSetState ($AEamounts, $GUI_FOCUS)
                EndIf

            If $fComboActive Then

                 $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                 _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)
                 GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney , $List1)
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($hcombo, False)

                _aeReset ()
            EndIf

            _blanker()

        Case     $cEnterPressed
            if GUICtrlSetState($List1,$GUI_enABLE) Then  ;<<<<THREE COLUMN LIST
                $countit = _GUICtrlListView_GetItemCount ( $List1 )
                ;If  _WinAPI_GetFocus() = $hEdit   Then ; old code
                 If _WinAPI_GetFocus() = $hEdit And GUICtrlRead($hcombo) Then   ;suggestion by Melba

                $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)

                GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney, $List1)

                _GUICtrlComboBox_ShowDropDown($hcombo, False)
                 GUICtrlSetState ($hcombo, $GUI_FOCUS)

                If _GUICtrlListView_GetItemCount ( $List1 ) > $countit and $hcombo <> ""  Then
                _aeReset ()
                EndIf
                EndIf
            EndIf
;below is the code for the second listview which has 2 columns
            if GUICtrlSetState($List2,$GUI_ENABLE) Then  ;<<< TWO COLUMN LIST
                $countit = _GUICtrlListView_GetItemCount ( $List2 )
                $MM =_GUICtrlComboBox_GetCurSel($combo_b)
                _GUICtrlComboBox_GetLBText($combo_b, $MM, $NN)
                GUICtrlCreateListViewItem(GUICtrlRead($combo_b)&"|"& $AEmoney, $List2)
            EndIf
;~                 If _GUICtrlListView_GetItemCount ( $List2 ) > $countit and $combo_b <> ""  Then
;~                 $NN = ""
;~                 GUICtrlSetData($AEamounts, "")
;~                 $AEMoney =0.0
;~                 GUICtrlSetState ($combo_b, $GUI_FOCUS)
;~                 _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
;~             EndIf
;end of second listview code


        Case $AEamounts

            $AEmoney = GUICtrlRead ( $AEamounts )
            if ($AEmoney/$AEmoney) = 1 And _IsPressed("0D") Then  ; checking for number entry
                GUICtrlSetState ($hcombo, $GUI_FOCUS)

            EndIf

            if ($AEmoney/$AEmoney) <> 1 Then
                MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                _aeReset ()
            EndIf


        Case $Button12

        Case $Button13

                Global $zzzz =_GUICtrlListView_GetSelectedIndices ( $List1 )
                DoubleClickFunc()

            Case $idFileitem
                _set()
            GUICtrlSetState($idLog, $GUI_unCHECKED)
            GUICtrlSetState ($combo_b, $GUI_FOCUS)
            $NN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0

    Case $idLog

        GUICtrlSetState($idFileitem, $GUI_unCHECKED)
        GUICtrlSetState($idLog, $GUI_CHECKED)
        GUICtrlSetState($List1,$GUI_enABLE);
        GUICtrlSetState($List1,$GUI_show)
        GUICtrlSetState($List2,$GUI_DISABLE);
        GUICtrlSetState($List2,$GUI_HIDE)
            GUICtrlSetState($hcombo,$GUI_enABLE); hide combo
            GUICtrlSetState($hcombo,$GUI_show)
    EndSwitch

    If _GUICtrlComboBox_GetDroppedState($hcombo) = True Then
        $fComboActive = True
    EndIf

    If _GUICtrlComboBox_GetDroppedState($combo_b) = True Then
        $fComboActive2 = True
    EndIf


WEnd

Func _Edit_Changed($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo) ; <<<<<<<<<<<<<<<<<<<<<
                Case $combo_b
                    _Edit_Changed($combo_b) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


Func _Blanker() ; trying to catch blank field
global $blankcount
$blankcount = _GUICtrlListView_GetItemCount ( $List1 )
for $i = (($blankcount) -1) to 0 step -1
if (_GUICtrlListView_GetItemText ( $List1, $i ))  = "" then
_GUICtrlListView_DeleteItem (  $List1, $i )
EndIf
Next
EndFunc



Func DoubleClickFunc()   ; for the delete button
    Global $DoubleClicked   = False
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    local $msgText = GUICtrlRead(GUICtrlRead($List1))
    local $msgText2 = StringTrimRight ( $msgText, 3 )
    local $msgCheck = MsgBox(4, "OK to : ", "Delete Entry:  " & $msgText2)
    If $msgCheck = 6 then
    _GUICtrlListView_DeleteItemsSelected ( $List1 )

    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $List1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

 Func _aeReset () ; for resetting all fields First Listview to blank in anticipation of the next entry
                $NNN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
            EndFunc

Func _set() ;Run  Setup
            GUICtrlSetState($idLog, $GUI_unCHECKED)
            GUICtrlSetState($List2,$GUI_enABLE);
            GUICtrlSetState($List2,$GUI_show)
            GUICtrlSetState($hcombo,$GUI_DISABLE); hide combo
            GUICtrlSetState($hcombo,$GUI_HIDE)
            GUICtrlSetState($List1,$GUI_DISABLE); hide combo
            GUICtrlSetState($List1,$GUI_HIDE)
            _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
GUICtrlSetState ($combo_b, $GUI_FOCUS)
    EndFunc

2. What is actually preventing my code from doing the same thing in regards to the two Listview. The Gui's seem to be right but the logic of what does what and when is messed up. 

I noticed I forgot to comment out something in my first post. Here it is(update) for the section of the code for List2.  Taking it out allows List1 input to correctly function BUT List2 is also impacted.

So I'm asking not only WHY you chose your process but also WHY mine is NOT working.  I need this to learn better coding not just copy and paste. I truly want to understand this stuff.

Thanks again.

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Answers:

- 1. I coded it that way because it seemed the right way to me. That does not necessarily mean that it is the best way - as Rudyard Kipling once said : "There are nine and sixty ways of constructing tribal lays, And every single one of them is right!". So I make no claims that I have the unique solution - but over 40 years of coding gives me a fair idea of what will work. And sorry about the cursor keys firing the combo - I forgot that would happen. I have prevented them for doing so in this version: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <ColorConstants.au3>
#include <GuiComboBox.au3>

Global $iActive = 1
Global $sCategoryData = "|A|B|C|D|E|F|G"
Global $sVendorData = "|Kaa|Kab|L|M|Naa|Nab|O|P|Q"

$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)

Local $idFilemenu = GUICtrlCreateMenu("&File")
Local $idRunmenu = GUICtrlCreateMenu("&Run")
Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu)

$cCombo_Category = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData($cCombo_Category, $sCategoryData)

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21)
GUICtrlSetState($AEamounts, $GUI_DISABLE)

$cCombo_Vendor = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData($cCombo_Vendor, "|Kaa|Kab|L|M|Naa|Nab|O|P|Q")
Local $tInfo
_GUICtrlComboBox_GetComboBoxInfo($cCombo_Vendor, $tInfo)
$hCombo_Vendor_Edit = DllStructGetData($tInfo, "hEdit")
$hCombo_Vendor = GUICtrlGetHandle($cCombo_Vendor)
GUICtrlSetState($cCombo_Vendor, $GUI_DISABLE)

$List1 = GUICtrlCreateListView("", 192, 72, 470, 260, $LVS_SINGLESEL, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($List1, "Vendor", 290)
_GUICtrlListView_AddColumn($List1, "Category", 90)
_GUICtrlListView_AddColumn($List1, "Amount", 160)

$List2 = GUICtrlCreateListView("", 15, 140, 145, 180, $LVS_SINGLESEL, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($List2, "Category", 90)
_GUICtrlListView_AddColumn($List2, "Amount", 160)
GUICtrlSetState($List2, $GUI_HIDE)

$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)

GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlCreateLabel("Amount", 104, 8, 50, 17)
GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)

$cEnterPressed = GUICtrlCreateDummy()
$cDummy_Vendor = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

; Flag to show combo should be fired
Global $bComboReady = False

While 1

    ; Check if combo list dropped and closed - signifies mouse used to select
    If _GUICtrlComboBox_GetDroppedState($cCombo_Vendor) = True Then
        While 1
            Sleep(10)
            If _GUICtrlComboBox_GetDroppedState($cCombo_Vendor) = False Then
                $bComboReady = True
                ExitLoop
            EndIf
        WEnd
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idLog
            GUICtrlSetState($List1, $GUI_SHOW)
            GUICtrlSetState($cCombo_Vendor, $GUI_SHOW)
            GUICtrlSetState($List2, $GUI_HIDE)
            $iActive = 1

        Case $idFileitem
            GUICtrlSetState($List2, $GUI_SHOW)
            GUICtrlSetState($List1, $GUI_HIDE)
            GUICtrlSetState($cCombo_Vendor, $GUI_HIDE)
            $iActive = 2

        Case $cCombo_Category
            GUICtrlSetState($AEamounts, BitOR($GUI_FOCUS, $GUI_ENABLE))


        Case $cEnterPressed
            Switch _WinAPI_GetFocus()
                Case GUICtrlGetHandle($AEamounts)
                    Switch $iActive
                        Case 1
                            GUICtrlSetState($cCombo_Vendor, BitOR($GUI_FOCUS, $GUI_ENABLE))
                        Case 2
                            GUICtrlCreateListViewItem(GUICtrlRead($cCombo_Category) & "|" & GUICtrlRead($AEamounts), $List2)
                            GUICtrlSetData($cCombo_Category, $sCategoryData)
                            GUICtrlSetData($AEamounts, "")
                            GUICtrlSetState($cCombo_Category, $GUI_FOCUS)
                            GUICtrlSetState($AEamounts, $GUI_DISABLE)
                    EndSwitch
                Case $hCombo_Vendor_Edit
                    ; Set flag to show Enter pressed
                    $bComboReady = True
                    GUICtrlSendToDummy($cDummy_Vendor)
            EndSwitch

        Case $cCombo_Vendor, $cDummy_Vendor
            ; Combo will be fired if keys used - but flag will not be set and so the code is not run
            If $bComboReady Then
                GUICtrlCreateListViewItem(GUICtrlRead($cCombo_Vendor) & "|" & GUICtrlRead($cCombo_Category) & "|" & GUICtrlRead($AEamounts), $List1)
                GUICtrlSetData($cCombo_Category, $sCategoryData)
                GUICtrlSetData($AEamounts, "")
                GUICtrlSetData($cCombo_Vendor, $sVendorData)
                GUICtrlSetState($cCombo_Category, $GUI_FOCUS)
                GUICtrlSetState($AEamounts, $GUI_DISABLE)
                GUICtrlSetState($cCombo_Vendor, $GUI_DISABLE)
                $bComboReady = False
            EndIf
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    $hWndFrom = $lParam
    $iCode = BitShift($wParam, 16) ; Hi Word
    If $hWndFrom = $hCombo_Vendor And $iCode = $CBN_EDITCHANGE Then
        _GUICtrlComboBox_AutoComplete($hCombo_Vendor)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
- 2. As to why your code does not work.... As I explained above, I found your code so hard to follow that I resorted to asking you what it was suppposed to do. I am afraid I am not prepared to go through it in great detail looking for the points where I believe it fails. Firstly I aam not prepared to spend the time and secondly (and I hope you will pardon me for saying this) it is such a mess that I would not know where to start. ;)

But that does not mean you have to be a "cut and paste" coder - the offer is still open if you want to know why I have made certain coding decisions. Although I hope most of them are obvious, there might well be something which is not so to other eyes. So do take advantage of my offer - just do not ask me to wade through your code in detail. :)

M23

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

Thanks M23.
That is fair and I can understand your position. Our two codes definitely show one is a Hobbyist and one is a Pro.
I will have to spend some time going through mine again attempting to discover my "Hobbyist" mistake or stand the chance of repeating it again.
I can also learn from yours by asking some questions, so forgive me if they sound stupid.
 
Please tell me about using $iActive and using Dummy in your process.
Also I picked up your use of nested Switch - something I guess I didn't retain when reading the help section.
 
When attempting to think of a process for this I kept thinking of it as a "gate" which swings two ways - one for List1 and the other for List2.
Link to comment
Share on other sites

  • Moderators

Hobbyist,

Thanks for understanding. But I assure you I am a hobbyist and not a "Pro" when it comes to coding. ;)

$iActive: This variable acts as a flag to show which ListView is active. It can only be changed by the $idLog & $idFileitem menuitems and determines the behaviour of the script when the accelerator key {ENTER} is pressed. If ListView 1 is active the focus passes to the Vendor combo; if ListView 2 then the data is added to the ListView - the Switch structure within the Case $cEnterPressed section determines the code to run.

Dummy Controls: These can be incredibly handy and I use them all the time. In this script there are 2:

 

$cEnterPressed is required for the {ENTER} Accelerator key and fires when that key is pressed. We then look to see which element of the GUI has focus - if it is the $AEamounts input we then check to see which ListView is active as described above. If it is the Vendor combo edit then we set a flag to show that the user was ready to accept whatever was shown. This flag $bComboReady is only set by pressing {ENTER} when the focus is on the Vendor combo edit or by selecting a combo item using the mouse (look at the _GUICtrlComboBox_GetDroppedState section of the code to see how this is determined). This is how I prevented items being added when merely scrolling through the combo with the cursor keys - if the flag is not set then the Case $cCombo_Vendor, $cDummy_Vendor code is not run.

Which brings us nicely onto the second dummy control - $cDummy_Vendor. We needed a way to fire the $cCombo_Vendor code when the {ENTER} Accelerator key was pressed and the focus was on the Vendor combo. We could have merely copied the same lines of code, but that is an anathema to any decent coder, so I opted for firing a dummy control which would, the next time round the loop, fore the correct Case and run the required code section.

I hope that helps. :)

M23

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

M23

Thanks for the description. And thanks for the set of patience you had with me. I saved your code and look forward to learning more from it.  So I'm off to dissect my code.

I have one question that keeps a mental roadblock for me or I am not understanding something.

If a control is "disabled", does that prevent it from being accessed or impacted upon?

My asking revolves around two comparisons.  Flag or If statement.

Your $iActive flag is for Listview activity. Its either this or that.  Isn't that similar to having an IF statement of some sort. IF this then List1 else List2? 

In other words is something like the following not workable(as a simplified example of my question):

if GUICtrlSetState($List1,$GUI_ENABLE) Then 

  do some stuff

elseif GUICtrlSetState($List2,$GUI_ENABLE) Then

  do other stuff

Endif

Edited by Hobbyist
Link to comment
Share on other sites

  • Moderators

Hobbyist,

The 2 approaches are functionally identical in that they identify which ListView is active - but one depends on the value of a simple integer variable whereas the other needs to run code to determine the state of a control each time. If you do this often enough you will see an execution time difference. And you would need to use BitAND(GUICtrlGetState($List1), $GUI_ENABLE) - even more complex. So overall I prefer a flag. :)

M23

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

Zedna

 

Thanks for the input. I'm putting your suggestion on my list to explore after my current solution is complete.

Hadn't even thought of such an approach, but want to try it as well to get more experience under my belt.

I may be back with questions at that point.

Hobbyist.

Link to comment
Share on other sites

M23,

I have done some "house cleaning" on my original code, after your solution and comments.  Using your switch approach made a world of difference and I am getting the results I desired at about 99%. I just want to know I can build it as well as copy it. I already have seen how much better yours is.

My $cEnterPressed has one glitch I don't understand why the behavior.  So while I am NOT asking for you to look at ALL of my code but rather just that piece you might be able to tell me where I am lacking. At this point I am not concerned with resetting things back to blanks/focus

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <MsgBoxConstants.au3>
 #include <GuiListView.au3>
#include <ColorConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=C:\Users\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)
$combo_b = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData(-1, "a|B|C|D|E|F|G")

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21);

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData(-1, "a|L|M|N|Na|O|P")

$List1 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)
GUICtrlSetState($List1,$GUI_enABLE)
_GUICtrlListView_AddColumn($list1, "Vendor",290)
_GUICtrlListView_AddColumn($list1, "Category", 90)
_GUICtrlListView_AddColumn($list1, "Amount", 160)

$List2 = GUICtrlCreateListview("", 15, 140, 145, 180,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List2, $COLOR_aqua)
_GUICtrlListView_AddColumn($list2, "Category", 90)
_GUICtrlListView_AddColumn($list2, "Amount", 160)
GUICtrlSetState($List2,$GUI_DISABLE);
GUICtrlSetState($List2,$GUI_HIDE)


$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Label1 = GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$Label2 = GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel(" Amount", 104, 8, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")


 Local $idRunmenu = GUICtrlCreateMenu("&Run") ;added August 3,2014
 Local $idLog = GUICtrlCreateMenuItem(" Log", $idRunmenu)
 Local $idFileitem = GUICtrlCreateMenuItem("Set ", $idRunmenu);added August 3,2014


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$cEnterPressed = GUICtrlCreateDummy()
global $listswitch ;switch between List 1 & 2
Global $MMM
Global $NNN
Global $AEmoney
Global $fComboSelected = False
Global $tInfo, $fComboActive = False
Global $fComboActive2 = False
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)

$hEdit = DllStructGetData($tInfo, "hEdit")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP

            If $fComboActive2 Then
                 GUICtrlSetState ($AEamounts, $GUI_FOCUS)
                EndIf

            If $fComboActive Then

                 $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                 _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)
                 GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney , $List1)
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($hcombo, False)

                _aeReset ()
            EndIf

        Case    $cEnterPressed
                    switch $listswitch

                        Case 2   ;<<< TWO COLUMN LIST>>>>>


                GUICtrlCreateListViewItem(GUICtrlRead($combo_b) & "|" & GUICtrlRead($AEamounts), $List2)
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )

                        Case 1    ;<<<<THREE COLUMN LIST>>>>>>>>

                $countit = _GUICtrlListView_GetItemCount ( $List1 ) ;used in _aeReset for blanks
                If _WinAPI_GetFocus() = $hEdit And GUICtrlRead($hcombo) Then
                GUICtrlCreateListViewItem(GUICtrlRead($hcombo) & "|" & GUICtrlRead($combo_b) & "|" & GUICtrlRead($AEamounts), $List1)
                    EndIf
                _GUICtrlComboBox_ShowDropDown($hcombo, False)
                GUICtrlSetState ($hcombo, $GUI_FOCUS)
                If _GUICtrlListView_GetItemCount ( $List1 ) > $countit and $hcombo <> ""  Then
                _aeReset ()  ; for resetting all fields First Listview to blank in anticipation of the next entry

                    EndIf

        EndSwitch

        Case $AEamounts   ;must check to see if number is entered, not string

            $AEmoney = GUICtrlRead ( $AEamounts )
            if ($AEmoney/$AEmoney) = 1 And _IsPressed("0D") Then ; checking for number entry
                    GUICtrlSetState ($hcombo, $GUI_FOCUS)
                          EndIf

            if ($AEmoney/$AEmoney) <> 1 Then
                MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                _aeReset ()  ; for resetting all fields First Listview to blank in anticipation of the next entry
            EndIf


        Case $Button12 ;future thoughts for saving entered data

        Case $Button13 ; Delete button to remove List1 items if desired

                Global $zzzz =_GUICtrlListView_GetSelectedIndices ( $List1 )
                DoubleClickFunc()

        Case $idFileitem

                GUICtrlSetState($idLog, $GUI_unCHECKED)
                GUICtrlSetState($idFileitem, $GUI_CHECKED)
                GUICtrlSetState($List2,$GUI_enABLE);
                GUICtrlSetState($List2,$GUI_show)
                GUICtrlSetState($hcombo,$GUI_DISABLE); hide combo
                GUICtrlSetState($hcombo,$GUI_HIDE)
                GUICtrlSetState($List1,$GUI_DISABLE); hide combo
                GUICtrlSetState($List1,$GUI_HIDE)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                    $listswitch =2


        Case $idLog

                GUICtrlSetState($idFileitem, $GUI_unCHECKED)
                GUICtrlSetState($idLog, $GUI_CHECKED)
                GUICtrlSetState($List1,$GUI_enABLE);
                GUICtrlSetState($List1,$GUI_show)
                GUICtrlSetState($List2,$GUI_DISABLE);
                GUICtrlSetState($List2,$GUI_HIDE)
                GUICtrlSetState($hcombo,$GUI_enABLE); hide combo
                GUICtrlSetState($hcombo,$GUI_show)
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                $listswitch = 1
    EndSwitch

    If _GUICtrlComboBox_GetDroppedState($hcombo) = True Then
        $fComboActive = True
    EndIf

    If _GUICtrlComboBox_GetDroppedState($combo_b) = True Then
        $fComboActive2 = True
    EndIf


WEnd

Func _Edit_Changed($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo) ; <<<<<<<<<<<<<<<<<<<<<
                Case $combo_b
                    _Edit_Changed($combo_b) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


Func DoubleClickFunc()   ; for the delete button
    Global $DoubleClicked   = False
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    local $msgText = GUICtrlRead(GUICtrlRead($List1))
    local $msgText2 = StringTrimRight ( $msgText, 3 )
    local $msgCheck = MsgBox(4, "OK to : ", "Delete Entry:  " & $msgText2)
    If $msgCheck = 6 then
    _GUICtrlListView_DeleteItemsSelected ( $List1 )

    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $List1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

 Func _aeReset () ; for resetting all fields First Listview to blank in anticipation of the next entry
                $NNN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
            EndFunc
 

, that will be fixable.

Here is the perplexing problem:

Using keyboard - List1 will NOT update unless I have gone into List2 and back. It doesn't matter if I have entered data in List2 or just clicked it (under Run). After that initial clicking of List2, List1 works just as it is supposed to.

Any way if you consider this a valid request for help, I would appreciate it.  Regardless thanks for all  the help you have passed my way. It has greatly helped.

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

That one is easy - you do not set a value for $listswitch when you declare it - so it does not have a value until you have actioned one of the menu items which set it and so neither of the Case statements fire when you press the {ENTER} accelerator key. :D

Just give the variable a default value when you declare it:

Global $listswitch = 1
And it is considered good coding practice to declare all Global variables at the top of the script - AutoIt can get all upset if you declare them in mid-script as you do. ;)

M23

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

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...