Sign in to follow this  
Followers 0
XLimas

Data list

13 posts in this topic

Hello everyone,

I'm creating little GUI where i'd want to read Departments names in one list and to get list of employees of certain department when it's chosen in another list. I decided to save all data in ini file. Sections are departments, keys are employee ids and value are name and surname.

First problem i'm getting is that i can't load Departments names in List, same as Employee names and surnames.

It's how i tried to load different data to the list:

Dim $aData[6] = ["One", "Two", "Three", "Four", "Five", "Six"]
$List1= GuiCtrlCreateList("", 5, 5, 150, 100)
GuiCtrlSetData(-1, $aData)

I know there should be used separator in GuiCtrlSetData, but i can't use it because data is in the file and it needs to be read somehow.

At all, i don't know or i'm going on a right way. Maybe i should save all the data in different way?

Does anyone have any ideas?

Share this post


Link to post
Share on other sites



XLimas,

Maybe this will give you the idea:

#include <GUIConstantsEx.au3>

$sIniFile = @ScriptDir & "\Dept.ini"

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

$hList_1 = GUICtrlCreateList("", 10, 10, 230, 200)
$hList_2 = GUICtrlCreateList("", 260, 10, 230, 200)

GUISetState()

$aDepts = IniReadSectionNames($sIniFile)
$sDepts = ""
For $i = 1 To $aDepts[0]
    $sDepts &= $aDepts[$i] & "|"
Next
GUICtrlSetData($hList_1, $sDepts)

$sCurrentDept = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $sSelectedDept = GUICtrlRead($hList_1)
    If $sSelectedDept <> $sCurrentDept Then
        $sCurrentDept = $sSelectedDept
        $aEmployees = IniReadSection($sIniFile, $sSelectedDept)
        $sEmployees = "|"
        For $i = 1 To $aEmployees[0][0]
            $sEmployees &= $aEmployees[$i][1] & "|"
        Next
        GUICtrlSetData($hList_2, $sEmployees)

    EndIf

WEnd

And here is the Ini I used:

[Dept 1]
ID101=OneOne
ID102=TwoOne
[Dept 2]
ID201=OneTwo
ID202=TwoTwo
[Dept 3]
ID301=OneThree
ID302=TwoThree

I hope this helps. Please ask if anything is unclear. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thats a great idea :mellow:

Thanks a lot!

Share this post


Link to post
Share on other sites

M23, if you are still around, i'd like to ask you some more help.

I want that all fields would be cleared after i press a button. For example, i'm registering employees to my data base (ini file) and after i filled all fields i press "Add" button. New employee is added, it's ok, but i'd like to add another one and all fields are already filled, i'd like that they were cleared after i added last employee.

Also, i saw somewhere (can't find it anymore), that it's possible to make some fields (Inputs, combo box, etc.) to be unactive, like i can't fill them until some other fields are filled.

At least give me some ideas where i can find anything about these.

Thanks in advance

Share this post


Link to post
Share on other sites

XLimas,

To clear a control, you set the content to a blank ("") with GUICtrlSetData.

To enable/disable a control, you use GUICtrlSetState with the $GUI_ENABLE/DISABLE states.

The Help file has all the details. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I'm moving on my GUI and i'd like to ask or it's a good way of getting strings from listview?

I was searching for examples, but most examples are so confusing, i'm just to weak to understand them, so i made my own.

I'm saving lines at the txt file, then i load them to array, sorting them ascending by one of the colums by my own algorith and then put them to the listview. Now i need to get the strings from the selected line in listview. I wrote working code and i don't know or it's ok, i'm afraid it will work slower than it could.

Just an example of how it looks like:

#include <GUIConstantsEx.au3> 
#include <GuiListView.au3>

Local $msg, $aItem, $sText
  
    GUICreate("GUI", 350, 400)   
    $listView = GuiCtrlCreateListView("One  |Two|Three|Four|Five|Six", 5, 5, 340, 130)
    GuiCtrlCreateListViewItem("Name|Surname|1985|Something|Something|Lalala", $listView)
    GuiCtrlCreateListViewItem("Name2|Surname2|1980|Something|Something|Tratata", $listView)
    GuiCtrlCreateListViewItem("Name3|Surname3|1975|Something|Something|Blalala", $listView)
    GuiCtrlCreateListViewItem("Name4|Surname4|1970|Something|Something|Blalala", $listView)
    $Button=GuiCtrlCreateButton("Go", 275, 140, 70, 20)
GUISetState()  

        
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button
            $line = GUICtrlRead($listView); gets line id
            $aItem = _GUICtrlListView_GetItemTextArray($ListView, $line-4); dunno why it's 4 more than selected one
            For $i = 1 To $aItem[0]
                $sText &= $aItem[$i] & @LF
            Next

            MsgBox(4160, "Information", $sText)
            $sText=""

    EndSelect
WEnd

Share this post


Link to post
Share on other sites

XLimas,

That is a good as anything else you could code. :mellow:

As to the need to subtract 4 - are you sittng comfortably?

When AutoIt creates controls it allocates them a ControlID - this is an index to an internal array which also holds the unique Windows handle to the control. Why does it do this? Read this topic for more detail. :(

When you use GUICtrlRead on a ListView you get, according to the Help file:

ListView: Control identifier (controlID) of the selected ListViewItem. 0 means no item is selected

So to get the line number you need to do a bit of maths on the returned value.

Look at the results in the SciTE console when you run this modified version of your script - you will see the Windows handle of the GUI and the ControlIDs of the controls within it:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Local $msg, $aItem, $sText

$hGUI = GUICreate("GUI", 350, 400)
ConsoleWrite("GUI: " & $hGUI    & @CRLF)
$listView = GuiCtrlCreateListView("One  |Two|Three|Four|Five|Six", 5, 5, 340, 130)
ConsoleWrite("ListView: " & $listView & @CRLF)
$LVItem = GuiCtrlCreateListViewItem("Name|Surname|1985|Something|Something|Lalala", $listView)
ConsoleWrite("LVItem 1: " & $LVItem & @CRLF)
$LVItem = GuiCtrlCreateListViewItem("Name2|Surname2|1980|Something|Something|Tratata", $listView)
ConsoleWrite("LVItem 2: " & $LVItem & @CRLF)
$LVItem = GuiCtrlCreateListViewItem("Name3|Surname3|1975|Something|Something|Blalala", $listView)
ConsoleWrite("LVItem 3: " & $LVItem & @CRLF)
$LVItem = GuiCtrlCreateListViewItem("Name4|Surname4|1970|Something|Something|Blalala", $listView)
ConsoleWrite("LVItem 4: " & $LVItem & @CRLF)
$Button=GuiCtrlCreateButton("Go", 275, 140, 70, 20)
ConsoleWrite("Button: " & $Button & @CRLF)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

I hope that is all clear. :lol:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

XLimas,

That is a good as anything else you could code. :mellow:

As to the need to subtract 4 - are you sittng comfortably?

When AutoIt creates controls it allocates them a ControlID - this is an index to an internal array which also holds the unique Windows handle to the control. Why does it do this? Read this topic for more detail. :(

When you use GUICtrlRead on a ListView you get, according to the Help file:

ListView: Control identifier (controlID) of the selected ListViewItem. 0 means no item is selected

So to get the line number you need to do a bit of maths on the returned value.

Look at the results in the SciTE console when you run this modified version of your script - you will see the Windows handle of the GUI and the ControlIDs of the controls within it:

I hope that is all clear. :lol:

M23

Yeah, it's clearer now.

So if i have two listviews with vary amount of lines every time, it will need some more effort to get right Control IDs of 2nd listview items, because 1st listview will be made of different amount of lines (Control IDs). Right?

Is there any other way to get exact line number?

Or i should try to get the ID number of last Control and subtract it from listview item ID?

Something like this?:

....
$label = GuiCtrlCreateLabel("", 0, 0); to get ID of listview, because he have next ID after this one
$listview = GuiCtrlCreateListView(...)
...

$line = GUICtrlRead($listview) - $label - 2

Share this post


Link to post
Share on other sites

XLimas,

So if i have two listviews with vary amount of lines every time, it will need some more effort to get right Control IDs of 2nd listview items, because 1st listview will be made of different amount of lines (Control IDs). Right?

Not quite. You have to use the same trick on both ListViews, but there is no need to worry about the size of the first. See the code below. :mellow:

Or i should try to get the ID number of last Control and subtract it from listview item ID?

Something like this?:

No need for a label - just use the ListView itself as you have to store the ControlID anyway:

....
; First ListView
$listview1 = GuiCtrlCreateListView(...) ; This is our start point for the first ListView
GuiCtrlCreateListViewItem(...) ; This line is +1
GuiCtrlCreateListViewItem(...) ; This line is +2
GuiCtrlCreateListViewItem(...) ; This line is +3
...
$line1 = GUICtrlRead($listview1) - $listview1 ; This gives you a 1-based line count for the items in the first ListView
...
; Now the second
$listview2 = GuiCtrlCreateListView(...) ; This is our start point for teh second ListView
GuiCtrlCreateListViewItem(...) ; This line is +1
GuiCtrlCreateListViewItem(...) ; This line is +2
GuiCtrlCreateListViewItem(...) ; This line is +3
...
$line2 = GUICtrlRead($listview2) - $listview2 ; This gives you a 1-based line count for the items in the second ListView
...

Incidentally, AutoIt has the Dummy control which is excellent for doing this sort of thing if there is not a convenient control to hand as here - go and look at it in the Help file. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Oh, my brains were overheated yesterday. I reread your post today and found out what you meant :mellow:

Also, i found out today that you can get text from your selected line without these ID countings.

You just need to use -1 as index in _GUICtrlListView_GetItemTextArray and you will get an array of strings of selected line :(

_GUICtrlListView_GetItemTextArray($control, -1)

Once again, thank you for helping. It's much easier now when i know what is Control IDs :lol:

Share this post


Link to post
Share on other sites

XLimas,

Always seems easier after a good night's sleep! :(

There are often many ways to do the same thing in AutoIt - glad you found the one that suits you. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Ok, i need advice again :mellow:

I'm registering some activities with my made GUI. It's like name, start date, end date, some other strings. All of them are saved to txt file as line. After some time i need to delete some activities and put them to another file, where are saved already made activities.

There is problem for me. How to delete certain line? I know line number in the file, but i can't find any function which could do it.

Of course, i can make algorithm which will save all lines to arrays, will skip the certain line, will delete all file info and replace it with new one without certain line. But i'm afraid it will be kinda slow. Maybe there is function who can delete certain line in file? Or maybe there is better way to do it?

I'm using v1.77 autoit. Should i get new version of it?

Share this post


Link to post
Share on other sites

XLimas,

To delete lines in a file, use _FileWriteToLine. From the Help file:

Remarks - If _FileWriteToLine is called with $fOverWrite as 1 and $sText as "", it will delete the line.

But then you must remember that all the subsequent lines move up by 1. :(

; ------

You are using SciTE v1.77, not AutoIt. SciTE is currently at at v1.79, so you could update from here if you wanted to get up-to-date.

AutoIt is currently at v3.3.4.0 stable and v3.3.5.6 Beta. You can tell which version you have by running this simple code:

MsgBox(0, "", @AutoItVersion)

You can download the latest versions from here. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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
Sign in to follow this  
Followers 0