Jump to content

Update Edit Box by clicking item in a list box


inm101
 Share

Recommended Posts

I'm able to update an Edit Box by highlighting an item in the list box and clicking a button. Here's my code:

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked"
    Local $add, $clear, $mylist, $close, $msg, $file, $file2
    
    GUICreate("My GUI list") ; will create a dialog box that when displayed is centered
    $file = GUICtrlCreateInput("", 10, 5, 300, 20)
    $file2 = GUICtrlCreateInput("", 10, 200, 300, 20)
    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUICtrlSetLimit(-1, 200)    ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                
                ;GUICtrlSetData($mylist, "You clicked button No1|")
                ;_WinAPI_ShowMsg("Current selction: " & _GUICtrlListBox_GetCurSel($mylist))
                ; _GUICtrlListBox_GetText($mylist, _GUICtrlListBox_GetCurSel($mylist))
                GUICtrlSetData(4,_GUICtrlListBox_GetText($mylist, _GUICtrlListBox_GetCurSel($mylist)))
                ;GUICtrlSetData($mylist, GUICtrlRead(3))
                ;GUICtrlSetData(3,"")
                ;MsgBox(4160, "Information", "Item Text: " & _GUICtrlListBox_GetText($mylist, 1))
                
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

What function do I need to use to update the edit box by just single or double clicking the item in the list box rather than having to update the edit box via the button?

Link to comment
Share on other sites

Hi,

For a single click you could use something like

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $msg, $mylist, $file2

    GUICreate("My GUI list")
    $file2 = GUICtrlCreateInput("", 10, 200, 300, 20)
    $mylist = GUICtrlCreateList("", 176, 32, 121, 97,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUICtrlSetLimit(-1, 200)
    GUICtrlSetData(-1, "List Item 1|List Item 2|List Item 3|List Item 4")
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $mylist
                GUICtrlSetData($file2, GUICtrlRead($mylist))
        EndSwitch
    WEnd
EndFunc   ;==>Example

For double click you'd use GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")..

To find out how to use a double click detection then have a look at the example in AutoIt help file under GuiListBox Management -> _GUICtrlListBox_Create

Cheers

Link to comment
Share on other sites

Hi,

For a single click you could use something like

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $msg, $mylist, $file2

    GUICreate("My GUI list")
    $file2 = GUICtrlCreateInput("", 10, 200, 300, 20)
    $mylist = GUICtrlCreateList("", 176, 32, 121, 97,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUICtrlSetLimit(-1, 200)
    GUICtrlSetData(-1, "List Item 1|List Item 2|List Item 3|List Item 4")
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $mylist
                GUICtrlSetData($file2, GUICtrlRead($mylist))
        EndSwitch
    WEnd
EndFunc   ;==>Example

For double click you'd use GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")..

To find out how to use a double click detection then have a look at the example in AutoIt help file under GuiListBox Management -> _GUICtrlListBox_Create

Cheers

Is there a way to get and set information from the same edit control?

In other words I'd like to update edit box via listbox click and update the listbox by entering edit box data. Is that possible given that the listbox is constantly updating the edit box?

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked"
    Local $add, $clear, $mylist, $close, $msg, $file, $file2
    
    GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $file = GUICtrlCreateInput("", 10, 5, 300, 20)
    
    $add = GUICtrlCreateButton("Add", 10, 135, 75, 25)
    
    $mylist = GUICtrlCreateList("buttons that have been clicked", 10, 32, 121, 97)
    GUICtrlSetLimit(-1, 200)    ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                GUICtrlSetData($mylist, GUICtrlRead(3))
            Case $mylist
                 GUICtrlSetData($file, GUICtrlRead($mylist))
        EndSelect
    WEnd
EndFunc   ;==>Example
Link to comment
Share on other sites

Hi, your welcome

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $msg, $mylist, $file2, $Button, $sGCR

    GUICreate("My GUI list")
    $file2 = GUICtrlCreateInput("", 10, 200, 300, 20)
    $Button = GUICtrlCreateButton("Add To List", 320, 200, 70, 20)
    $mylist = GUICtrlCreateList("", 176, 32, 121, 97, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUICtrlSetLimit(-1, 200)
    GUICtrlSetData(-1, "List Item 1|List Item 2|List Item 3|List Item 4")
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $mylist
                GUICtrlSetData($file2, GUICtrlRead($mylist))
            Case $Button
                $sGCR = GUICtrlRead($file2)
                If $sGCR <> "" Then GUICtrlSetData($mylist, $sGCR)
        EndSwitch
    WEnd
EndFunc   ;==>Example

Cheers

Edited by smashly
Link to comment
Share on other sites

  • 5 months later...

This is strange. I cannot figure out how to enable a horizontal scroll bar in a listbox. Apparently I can even limit the range that it can scroll, but I cannot enable it. Any suggestions?

Local $button, $msg, $aFound
    
    $ListGUI = GUICreate("Search for Certificates", 500, 250, -1, -1)
    
    $listview = GUICtrlCreateList("", 10, 10, 480, 150, -1) ;<----No horizontal scroll bar
    ;GUICtrlSetLimit(-1, 200)
    $btnSearch = GUICtrlCreateButton("Search", 150, 190, 90, 30, $BS_DEFPUSHBUTTON);Default button pressed when "Enter" key is pressed.
    $btnInstall = GUICtrlCreateButton("Install", 250, 190, 90, 30)
    GUICtrlSetState($BtnInstall, $GUI_DISABLE)
    
    GUISetState(@SW_SHOW)
Edited by nasim007
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...