Jump to content

List Box help


 Share

Recommended Posts

Ok, so I have a GUI, and it processes some basic calculations.

The history of these calculations is currently stored in a list box like the image below (the large bottom left box)

Posted Image

I would like it so the common data, next to STN data is not repeated, so its more clear which data is in the correct 'group'.

does anyone have an easy way of formatting this, so it looks correct? Like this

Posted Image

Or should I be doing it another way?

Many thanks in advance, and merry Christmas :-)

I thought about a listview item, but I always have issues with column widths etc.

Edited by civilcalc
Link to comment
Share on other sites

  • Moderators

civilcalc,

Can you please post some code - specifically the code which formats the text that will be sent to the ListBox and that which actually sends it. :)

My initial thoughts are that you store the "STN..." text in a variable and then use code to remove it from subsequent lines until it changes. But without sight of the code I can offer nothing more concrete. ;)

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

Melba, bare with my on this one, things are clear in my head, but are often hard to convey.

First the graph has its own array;

$baby1_grapharray

0-100.000-100.000

1-200.000-200.000

Which stores the output, if line 0 is unchanged, ie the same station, the array is re-dimmed and the new target is added;

$baby1_grapharray

0-100.000-100.000

1-200.000-200.000

3-300.000-300.000

If line 0 has changed a new array is created;

$baby1_grapharray

0-200.000-200.000

1-300.000-300.000

using this code

$stationeast  = GUICtrlRead($stn_e)
$stationnorth = GUICtrlRead($stn_n)
$targeteast   = GUICtrlRead($trg_e)
$targetnorth  = GUICtrlRead($trg_n)

If $grapharray[0][0] = $stationeast And $grapharray[0][1] = $stationnorth Then
  $count = UBound($grapharray)
  ReDim $grapharray[$count+1][2]
  $grapharray[$count][0] = $targeteast
  $grapharray[$count][1] = $targetnorth
Else
  Dim $grapharray[2][2]
  $grapharray[0][0] = $stationeast
  $grapharray[0][1] = $stationnorth
  $grapharray[1][0] = $targeteast
  $grapharray[1][1] = $targetnorth
EndIf

The graph is drawn, like in the pictures, I wont put the code here, as its massive.

Then the history is updated using this code;

$leftupdate  = "STN "&Guictrlread($baby1_1)&","&Guictrlread($baby1_2)
$midupdate   = "  ---  WCB "&GUICtrlRead($baby1_3)
$rightupdate = "  ---  DIST "&GUICtrlRead($baby1_4)

If UBound($baby1_grapharray) < 3 Then
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
Else
  $leftupdate = "                           "
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
EndIf

The else statement basically says if there are more than 1 target(s) in the array, replace the 'leftupdate' with a blank string. I know I can get this string length to match the original string length, and I know I can format the mid and right updates to align correctly, but the blank string is causing the update to appear out sync with the station it is associated with. The future of this the onevent triggered when the user click the line in the history, using this function;

Func _baby1_history()
$item = _GUICtrlListBox_GetCurSel($baby1_history)
$text = _GUICtrlListBox_GetText($baby1_history,$item)
$text = StringReplace($text,"STN ","")
$text = StringReplace($text,"  ---  WCB ",",")
$text = StringReplace($text,"  ---  DIST ",",")
$string = StringSplit($text,",")
GUICtrlSetData($baby1_1,$string[1])
GUICtrlSetData($baby1_2,$string[2])
GUICtrlSetData($baby1_3,$string[3])
GUICtrlSetData($baby1_4,$string[4])
baby1calc()
EndFunc

Basically allowing the user to 'replay' an older calculation.

Thanks

Link to comment
Share on other sites

  • Moderators

civilcalc,

Sorry, this will have to wait until tomorrow - it has been a long day. :)

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

$leftupdate  = "STN "&Guictrlread($baby1_1)&","&Guictrlread($baby1_2)
$midupdate   = "  ---  WCB "&GUICtrlRead($baby1_3)
$rightupdate = "  ---  DIST "&GUICtrlRead($baby1_4)

If UBound($baby1_grapharray) < 3 Then
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
Else
  $leftupdate = "                           "
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
EndIf

Global $leftupdate_prev = ''
Global $leftupdate_empty = _StringRepeat(' ',19)

...

$leftupdate  = "STN "&Guictrlread($baby1_1)&","&Guictrlread($baby1_2)
If $leftupdate <> $leftupdate_prev Then
    $leftupdate_prev = $leftupdate
Else
    $leftupdate = $leftupdate_empty
EndIf
$midupdate   = "  ---  WCB "&GUICtrlRead($baby1_3)
$rightupdate = "  ---  DIST "&GUICtrlRead($baby1_4)

If UBound($baby1_grapharray) < 3 Then
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
Else
  $leftupdate = "                          "
  GUICtrlSetData($baby1_history,$leftupdate&$midupdate&$rightupdate)
EndIf

EDIT:

If you want help with listview column widths then don't hesitate to ask

istview is much better for this purpose than listbox

Edited by Zedna
Link to comment
Share on other sites

If you want help with listview column widths then don't hesitate to ask

istview is much better for this purpose than listbox

Zenda, yes please! Ideally what I am looking for is the station in the left column only on the first line, any repeats of this station will add the 'targets' underneath it (like in the photo-shopped second photo), the user can then click on any of the targets to 'replay' the calculation. I am not sure if the widths of the columns in a listview box can be locked in some way? I am hoping you are a listview expert :)

Link to comment
Share on other sites

  • Moderators

civilcalc,

Sorry I did not get back to you - Christmas got in the way. ;)

I agrer with Zedna that ListViews are much better suited to your purpose. To set the widths of the columns you can use (unsurprisingly) _GUICtrlListView_SetColumnWidth. Locking the column widths and detecting clicks on the subitems is done like this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

$hGui = GUICreate("Test", 250, 250)

$hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 10, 10, 230, 160)
For $i = 1 To 6
    GUICtrlCreateListViewItem("Item " & $i & "1|Item " & $i & "2|Item " & $i & "3", $hListView)
Next

$hButton = GUICtrlCreateButton("Lock Columns", 75, 200, 100, 30)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            Switch GUICtrlRead($hButton)
                Case "Lock Columns"
                    GUICtrlSetData($hButton, "Unlock Columns")
                    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView))) ; Lock listview header
                Case "Unlock Columns"
                    GUICtrlSetData($hButton, "Lock Columns")
                    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView))) ; Unlock listview header
            EndSwitch

    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate($tagNMLISTVIEW, $lParam)

    If @error Then Return
    Switch DllStructGetData($tStruct, 3)
        Case $NM_DBLCLK ; Look for the double click
            ConsoleWrite("Row: " & DllStructGetData($tStruct, "Item") + 1 & " - Col: " &DllStructGetData($tStruct, "SubItem") + 1 & @CRLF)
    EndSwitch

EndFunc   ;==>On_WM_NOTIFY

I hope that makes up for my tardiness. All clear? :)

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

Melba,

No worries about Christmas, hope you had a good one.

I had seen the _GUICtrlListView_SetColumnWidth function, but with not being able to lock them, I didnt bother to use it.

I can see how it works, but I dont think I could ever have figured that out.

I am thinking of also writing the data to an .ini file so each section will be under the station data, and each target data will be stored as a 'key'. I think I can then retrieve the data better to re-draw the graph, what do you think?

Civilcalc

Link to comment
Share on other sites

  • Moderators

civilcalc,

Sounds like a reasonable plan, but remember that ini files are limited to 64k in size using the normal Ini* functions, with a section limited to 32k. I have no idea of the size of your stored data, but that is worth bearing in mind. There is a UDF out there which can deal with ini files over this size, but I have never used it. :)

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

civilcalc,

Sounds like a reasonable plan, but remember that ini files are limited to 64k in size using the normal Ini* functions, with a section limited to 32k. I have no idea of the size of your stored data, but that is worth bearing in mind. There is a UDF out there which can deal with ini files over this size, but I have never used it. :)

M23

Ah, I didnt know that. Any idea how many characters 32k is? I could create an ini file for each station I guess, I am not sure if I want to save the data after the user has closed the main GUI, as I couldnt see any need to re-use the data after I have closed the GUI, but I what I want/do is not what someone else might want to do. Failing that maybe a giant array.

Thanks

EDIT Melba, is this function you made, is it possible to use it with oneventmode 1 ?

The listview is looking pretty funky by the way ;)

Ok, I figured it out, I added two replay and delete buttons under the graph for the user to click.

Edited by civilcalc
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...