Jump to content
Trax

Need help with List Boxes

Recommended Posts

First I am not really sure I should be using a list box but can't find much better. It is a Window used to display a single value only. I don't really need a list. So is a ListBox what I should be using?

Anyway.... I want to put a value in a ListBox and have it be the only value in that ListBox. The only way I have found to do it is to delete what is there first then add it:

_GUICtrlListBox_DeleteString($List4, 0)
_GUICtrlListBox_AddString($List4, $Calculated15MinPeriod)

Isn't that a command that will simply overwrite whatever is there with a new value? A single command rather then having to delete it first?

 

Thanks in advance!

 

Share this post


Link to post
Share on other sites

Sounds like you're looking for _GUICtrlListBox_SetItemData ;)

I think that a list box isn't really what you're looking for though... you can use an Input if there is text that needs to be able to be edited by the user, or a Label for text that doesn't.


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites

Thanks @seadoggie01 . I tried a lot of _GuiCtrlListBox functions but overlooked that one. The boxes are display only. i.e. read data, move to control. Loop. No input or editing. 

Share this post


Link to post
Share on other sites

Yep. Having a mental block on this one. 

Here is what I had and it seems to work. It would display in the ListBox:

_GUICtrlListBox_DeleteString($List1, 0)
_GUICtrlListBox_AddString($List1, $CurrentDate)

 

I tried this and nothing displayed in the ListBox:

_GUICtrlListBox_SetItemData($List1, 0, $CurrentDate)

Share this post


Link to post
Share on other sites

No _GUICtrlListBox_SetItemData replaces the internal value of an item list box.  If you want to change the displayed value use _GUICtrlListBox_ReplaceString

Share this post


Link to post
Share on other sites
Posted (edited)
21 hours ago, Trax said:

First I am not really sure I should be using a list box but can't find much better. It is a Window used to display a single value only. I don't really need a list. So is a ListBox what I should be using?

You obviously haven't spent enough time reading the help file's documentation on GUI's and the GUI controls that are available.  If you know that you want to "display a single value only", what would make you come to the conclusion that a ListBox would be a good choice to display a single value?  What is it about the words "single value" makes you think a control with the word "List" in its name would be applicable?

Maybe now is a good time to go back to the help file and do a little more research.  If you are looking for a good starting point to get a visual representation of many of the controls that are available, then I would start with the help file topic named "GUI Concepts".  There, among other things, you will find a list of controls, a brief description of each control, and a sample GUI that displays several of the controls,  Here's a link to the online version of the GUI Concepts help file page.  That page also has a related example script that displays the sample GUI so you can you can see an example of how to implement those controls and how a user can interact with them.  The example script can be found in ...\AutoIt3\Examples\GUI\SampleControls.au3.  I would suggest copying that script to a different location so that you can modify the script as necessary while you are learning which ones may be best for your needs and how to manipulate them.

To answer your specific question, if it is a single line of information that needs to be displayed and overwritten as needed, a "Label" control might be a better choice.  If you need a user to be able to enter a single value, then an "Input" control might be a good choice.  Not knowing more about the data and it's intended use within your GUI, those are just guesses based on you stated requirement.

Edited by TheXman

Share this post


Link to post
Share on other sites

@TheXman that is easy for you to say. You have probably been doing AutoIT for a couple years with an emphasis on GUI. To say the least the documentation is daunting. I have spent more time in the Wiki and reading function descriptions then I really want to think about. I put out a good effort before asking the question. 

Thanks you for the answer.....

 

Share this post


Link to post
Share on other sites
Posted (edited)

sound like your just building a status box.  you can use a sunken label and use a simple GuiCtrlSetData to update whenever you want.

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

$iLabelNbr = 1
GUICtrlCreateLabel("Label " & $iLabelNbr & ", Normal", 10, 30, 200, 20)

$iLabelNbr += 1
$hLbl2 = GUICtrlCreateLabel("Label " & $iLabelNbr & ", Sunken", 10, 60, 200, 20, $SS_SUNKEN)

$hBtn = GUICtrlCreateButton("Update Sunken Label", 10, 120, 120, 20)
GUISetState(@SW_SHOW) ; will display an empty dialog box

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hBtn
            $iLabelNbr += 1
            GUICtrlSetData($hLbl2, "Label " & $iLabelNbr & ", Sunken")
    EndSwitch

WEnd

 

edit:  I've been using AutoIt before it had the ability to create a GUI and I find new things it's capable of on a weekly basis.

Edited by BigDaddyO

hmm... I guess I have to have a signature...

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...