Jump to content

Multi column list box


Jewtus
 Share

Go to solution Solved by Melba23,

Recommended Posts

I'm sure I'm missing something very obvious, but how do I make a list box that has two or more columns?

This is what I have

 

$Results = GUICtrlCreateList("", 8, 56, 209, 448)
 
And I insert data 
GUICtrlSetData($Results,$parse)

$parse is a list of results separated by a |

How can I add a date column?

 

Link to comment
Share on other sites

  • Moderators
  • Solution

Jewtus,

A multicolumn ListBox is not what you think - all it does is align the elements in columns like this:

1   5   9
2   6  10
3   7
4   8
If you want to have rows of associated elements then you need a ListView - which is a very different beast. ;)

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

Now if I could only figure out how to return the specific element I have highlighted....

_GUICtrlListView_GetItemText($FoundAccountBox,0,0) 

gets the column I want but it doesn't know which row I have selected...

Link to comment
Share on other sites

  • Moderators

Jewtus,

In the same UDF you will find _GUICtrlListView_GetSelectedIndices - looking in the Help file is always worth a try. ;)

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

Yup, that is what I have been doing, but this is the trouble I'm having:

$Number = _GUICtrlListView_GetItemText($FoundAccountBox,_GUICtrlListView_GetSelectedIndices($FoundAccountBox,0),0)

That doesn't seem to work, where

$Number = _GUICtrlListView_GetItemText($FoundAccountBox,0,0)

Gets me the first column first row value.

_GUICtrlListView_GetSelectedIndices($FoundAccountBox,0)

does get my the selected row, but it doesn't seem to execute when I have it in line (or even if I specify it as a variable first)

I even tried to swap the index and subindex thinking maybe I was confused, and the weirdest part... 

_GUICtrlListView_GetItemText($FoundAccountBox,0,_GUICtrlListView_GetSelectedIndices($FoundAccountBox,0))

That kicks up row 1 and the highlighted row's column value

Edited by Jewtus
Link to comment
Share on other sites

  • Moderators

Jewtus,

<sigh>

What does the Help file say is returned by ,_GUICtrlListView_GetSelectedIndices? Can you use it directly as a parameter in another functions? :huh:

Answers:

- 1. An array.

- 2. No.

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

You'd probably want to use _GUICtrlListView_GetItemTextString to get all the columns of the row instead of just the first item in the row and then have to loop through the columns one at a time.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Jewtus,

<sigh>

What does the Help file say is returned by ,_GUICtrlListView_GetSelectedIndices? Can you use it directly as a parameter in another functions? :huh:

Answers:

- 1. An array.

- 2. No.

M23

Yes, I did read that it returns an array, which is why I originally put 

_ArrayDisplay($Number2)

when I was testing it. The array is never displayed, however I also had this line:

MsgBox(0,"",$Number&@CRLF&$Number2)

and the number2 does show the selected row value. That is when I tried swapping the index and subindex and got the column corresponding to the row I had highlighted. That is what has me so confused....

Link to comment
Share on other sites

You'd probably want to use _GUICtrlListView_GetItemTextString to get all the columns of the row instead of just the first item in the row and then have to loop through the columns one at a time.

That is what I needed... This worked for me:

$test= StringSplit(_GUICtrlListView_GetItemTextString($FoundAccountBox),"|",2)[0]
Link to comment
Share on other sites

  • Moderators

Jewtus,

I see now you are using this code (why do people not space their code rather than cramping it together? :huh:):

_GUICtrlListView_GetSelectedIndices($FoundAccountBox,0)
0 is interpreted as False - so you are actually getting a delimited string which explains why you do not get an array. You still need to extract the index from the string. ;)

I would stick with the array and just use the [1] element. :)

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

If you only want one item selected at a time, create the ListView with $LVS_SINGLESEL as one of the styles for the LV, if you're using the default style settings for the LV then that value is always applied. This way you can use _GUICtrlListView_GetSelectedIndices with the $bArray parameter set to 0 and you will only get a single item's index number. No stringsplitting needed that way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If you only want one item selected at a time, create the ListView with $LVS_SINGLESEL as one of the styles for the LV, if you're using the default style settings for the LV then that value is always applied. This way you can use _GUICtrlListView_GetSelectedIndices with the $bArray parameter set to 0 and you will only get a single item's index number. No stringsplitting needed that way.

I tried this and even wit LVS_SINGLESEL, when I use _GUICtrlListView_GetSelectedIndices,  I still get a | delimited string. 

This is what I tried:

$Results = GUICtrlCreateListView("", 8, 58, 209, 448,$LVS_SINGLESEL)

and 

MsgBox(0,"",_GUICtrlListView_GetItemTextString($Results,0))

I do have it working with the string split though so I think this topic can be closed.

Thanks fellas!

Link to comment
Share on other sites

You misread what I wrote, I didn't say use _GUICtrlListView_GetItemTextString, I said use _GUICtrlListView_GetSelectedIndices with the $bArray parameter set to 0 to get the index number of the selected item.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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