Jump to content

[SOLVED] Display two columns in list?


Recommended Posts

Hello

I just need to display a two-column list of items with Name + Phone number and let the user select one or more items and click OK.

I went through the samples in \Examples\Helpfile\, and it seems like the ListView object does the job but it's pretty complicated (_GUICtrlListView_CancelEditLabel.au3).

I was wondering if I couldn't just use the basic ListBox object instead, use a TAB or some caracter to separate the two items, and use a regex to extract the phone number of all selected lines when the user clicks on OK? Not as pretty as a real grid, but it probably makes for easier code.

If that sounds like a good idea, would someone have some code handy that I could check?

Thank you.

Edited by littlebigman
Link to comment
Share on other sites

Mmm... The app crashes when I add strings ;)

Global $arr[2] = ["John" + @TAB + "123", "Jane" + @TAB + "456"]

...

$List1 = GUICtrlCreateList("", 8, 24, 241, 136, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
Local $i
For $i = 0 to UBound($arr) - 1
    ;CRASH: autoit3.exe has encountered a problem and needs to close.
    _GUICtrlListBox_AddString($List1, $arr[$i])
Next
Link to comment
Share on other sites

Turns out AutoIT doesn't allow "+" to concatenate strings, but rather "&":

Global $arr[2] = ["John" & @TAB & "123", "Jane" & @TAB & "456"]

However, the TAB character is ignored in the ListBox control, so the two "columns" are displayed with no space" between them. Does this control simply not allow this character, or is there some switch I should use when creating it?

Link to comment
Share on other sites

  • Moderators

littlebigman,

You cannot have columns in a List control, you need a ListView. But you do not necessarily need the ListView UDF, AutoIt has a native ListView control which you use like this: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hLV = GUICtrlCreateListView("Col 1|Col2", 10, 10, 480, 300)

For $i = 1 To 10
    GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $hLV)
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Please ask if you have any questions. :)

M23

P.S. You can edit your posts to add detail - adding as many extra posts as you are at the moment is rather frowned on here. ;)

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

You cannot have columns in a List control, you need a ListView. But you do not necessarily need the ListView UDF, AutoIt has a native ListView control which you use like this: :)

Thanks much for the code. I'll give it a shot.

P.S. You can edit your posts to add detail - adding as many extra posts as you are at the moment is rather frowned on here. ;)

Right, but I do this on purpose: In case some other newbie looks in the archives months from now, it's easier to quickly find an answer if a thread only deals with a single problem ;)

Link to comment
Share on other sites

  • Moderators

littlebigman,

It is not the number of topics, but the number of immediately successive individual posts within them - like the first 3 above. ;)

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