Jump to content

Switching the data of list


Recommended Posts

Need to organize hot-switch of variables from 1 to 5 and from 5 to 1 with full exchange of data in array. (but not reverse - numbers set just as simple example) Any suggestions about it? Same as in screenshots. In full project the data for gui reads from ini-file

post-48437-1240006235_thumb.jpg post-48437-1240006222_thumb.jpg

I thought about:

1) kill and recreate window (as a variant but not the best choice)

2) create ALL checkbox in the listview but set visible/invisible if is it possible (I think this is the hardest way)

3) kill gui control "listview" and create new with the same name - this does not help.. Why? Don't know...

the part of code of trouble:

#NoTrayIcon
;#include <Debug.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <GUIScrollBars.au3>
#include <INet.au3>
#include <ListBoxConstants.au3>
#include <ListviewConstants.au3>
#include <ScrollBarConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
global $conf, $conf1, $conf2, $treeOne, $c1, $c
$ini_list1 = _ArrayCreate("")
$tree_list_one = _ArrayCreate("")


$Form1 = GUICreate("Form1", 200, 200)
$conf1 = GUICtrlCreateButton("conf1",120, 8, 80, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$conf2 = GUICtrlCreateButton("conf2",120, 24, 80, 17)
$Bbutton1 = GUICtrlCreateButton("4test", 40, 180, 60, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$treeOne = GUICtrlCreateListView("Items",0, 8, 120, 120, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($treeOne, 0, $LVSCW_AUTOSIZE_USEHEADER)
For $c = 1 To 5 ; setting the data (this example has just simple cycle)
    _ArrayAdd($ini_list1, $c)
Next
_ArrayReverse ($ini_list1)
_ArrayPop($ini_list1)
If $c <> 0 Then
    dim $tree_list_one[$c]
EndIf
$c = 0


GUISetState(@SW_SHOW)


if $conf = 0 Then
    _check(0)
endif


func _check ($lab)
; _check(1)
    if $lab = 1 then
        For $c = 5 To 1 ; 5,4,3,2,1
            _ArrayAdd($ini_list1, $c)
        Next
        For $c1 = 0 To $c
;~          _ArrayDisplay($ini_list1,"$ini_list1")
;~          _ArrayDisplay($tree_list_one,"$tree_list_one")
            GUICtrlSetData($tree_list_one[$c1], _ArrayPop($ini_list1), $treeOne)
        Next
    return 
;   _check(2)
    elseIf $lab = 2 then
        For $c = 1 To 5 ; 1,2,3,4,5
            _ArrayAdd($ini_list1, $c)
        Next
        For $c1 = 0 To $c-2
            GUICtrlSetData($tree_list_one[$c1], _ArrayPop($ini_list1), $treeOne)
        Next
    return 

    else 
        For $c = 1 To 5
            _ArrayAdd($ini_list1, $c)
        Next
        For $c1 = 0 To $c-2
            GUICtrlSetData ($tree_list_one[$c1],GUICtrlCreateListViewItem(_ArrayPop($ini_list1), $treeOne))
;~          _ArrayDisplay($ini_list1,"$ini_list1")
;~          _ArrayDisplay($tree_list_one,"$tree_list_one")
        Next
    return
    endif 
endFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $conf1
            _check(1)
        Case $conf2
            _check(2)
    EndSwitch
WEnd
Link to comment
Share on other sites

No. I mean to:

1) create the treeviewlist with the array[$i]

2) put the $c into array value

3) create GUI with default data of function _check(0)

4) wait for switch and then check

a) if pressed (1) then set the value of array 5...1 and show it in the GUI

B) if pressed (2) then set 1...5 and show it.

Later the shown data need to be checked by user and worked by script for searching and sending checked data to the server.

this is not the exactly input values, but for this example.

Link to comment
Share on other sites

I don't think he wants to simply sort the items...1 to 5 was just an example, items could be any strings (I think?!?!?!?).

Do you want to keep the array as it is, or do you want it to be reversed along with the list view?

Does this help any?:

#include <ListviewConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)

Global $aArray[5] = [1,2,3,4,5]
Global $aArrayCopy[1]

GUICreate("",200,150)

$LV = GUICtrlCreateListView("Items",10,10,120,120,-1,$LVS_EX_CHECKBOXES)

GUICtrlCreateButton("Forward",140,10,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")
GUICtrlCreateButton("Reverse",140,40,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")

GUISetState()
While 1
    Sleep(100)
WEnd

Func PopulateLV()
    $aArrayCopy = $aArray
    If @GUI_CtrlId = 5 Then _ArrayReverse($aArrayCopy)
    _GUICtrlListView_DeleteAllItems($LV)
    For $i In $aArrayCopy
        GUICtrlCreateListViewItem($i,$LV)
    Next
EndFunc
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Yes.. it must be different strings, what should be read from ini.

Your code with reversing first array with second is usefull but not for this project... ini consists from 2 parts:

1) [conf1]

data1=x

data2=y

2) [conf2]

data3=a

data4=b

Thanx for code, if anyone has another idea, please write it ^_^

Link to comment
Share on other sites

ok, wild-stab-in-the-dark number 2:

#include <ListviewConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)

Global $aArray

GUICreate("",200,150)

$LV = GUICtrlCreateListView("Items",10,10,120,120,-1,$LVS_EX_CHECKBOXES)

GUICtrlCreateButton("Conf1",140,10,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")
GUICtrlCreateButton("Conf2",140,40,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")

GUISetState()
While 1
    Sleep(100)
WEnd

Func PopulateLV()
    
;----- Read different ini sections into array, depending on button pressed -----
    Switch @GUI_CtrlId
        Case 4;Conf1
            $aArray = IniReadSection("data.ini","conf1")
        Case 5;Conf2
            $aArray = IniReadSection("data.ini","conf2")
    EndSwitch
    
;----- populate LV with ini values -----
    For $i = 1 to UBound($aArray) - 1
        GUICtrlCreateListViewItem($aArray[$i][1],$LV)
    Next

EndFunc

.... this one loads ini keys & values into the global array from "data.ini" from different sections depending on which button was pressed.

Listview items are then created from the array.

Any closer?

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

this is closer... works as my first try. But the same(old) problem - the list now adds itselfs...

for example:

input from conf1:

[conf1]

ID=000001

ID=000002

ID=000003

ID=000004

[conf2]

ID=000005

ID=000006

ID=000007

ID=000008

After click - conf 2 button - it just adds after conf 1 and the same - if click 1 it adds after last clicked.

Result of cross-clicking:

000001

000002

000003

000004

000005

000006

000007

000008

000001

000002

000003

000004

000001

000002

000003

000004

Same method (more harder then your) was done before in my project.. But I hope it may be the way to clear first list without deleting (for re-call it later if press button conf1) and creating new ^_^

Edited by P0ZiTR0N
Link to comment
Share on other sites

  • Moderators

this is closer... works as my first try. But the same(old) problem - the list now adds itselfs...

for example:

input from conf1:

[conf1]

ID=000001

ID=000002

ID=000003

ID=000004

[conf2]

ID=000005

ID=000006

ID=000007

ID=000008

After click - conf 2 button - it just adds after conf 1 and the same - if click 1 it adds after last clicked.

Result of cross-clicking:

000001

000002

000003

000004

000005

000006

000007

000008

000001

000002

000003

000004

000001

000002

000003

000004

Same method (more harder then your) was done before in my project.. But I hope it may be the way to clear first list without deleting (for re-call it later if press button conf1) and creating new ^_^

Your description of what you need/want really suck. You should take more time trying to figure out how to explain yourself. And, I commend you on providing example code (that doesn't work at all ;) , but it didn't explain your situation either).

A stab in the dark as andybiochem did (there shouldn't have to be "stabs"):

;~ #NoTrayIcon; When your submitting testing code, unless you know what you're doing, don't remove the tray icon!
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
; Don't add unnecessary includes to your test code

#Region Global Data
Global $s_data_ini = "data.ini"
#Region Global Data

#Region GUI Creation
Global $h_main_gui = GUICreate("My GUI", 200, 200)
Global $i_button_conf1 = GUICtrlCreateButton("Conf1", 120, 8, 80, 17)
Global $i_button_conf2 = GUICtrlCreateButton("Conf2", 120, 24, 80, 17)
;~ Global $i_button_test = GUICtrlCreateButton("4Test", 40, 180, 60, 120); No idea what you're doing with this button
Global $h_lv_main = _GUICtrlListView_Create($h_main_gui, "Items", 0, 8, 120, 120)
_GUICtrlListView_SetExtendedListViewStyle($h_lv_main, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($h_lv_main, 0, $LVSCW_AUTOSIZE_USEHEADER)
#EndRegion GUI Creation

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $i_button_conf1
            _conf_data($h_lv_main, $s_data_ini, "conf1")
        Case $i_button_conf2
            _conf_data($h_lv_main, $s_data_ini, "conf2")
    EndSwitch
WEnd

Func _conf_data($h_lv, $s_ini, $s_section)
    Local $a_ini = IniReadSection($s_ini, $s_section)
    If @error Then Return SetError(1, 0, 0)
    
    _GUICtrlListView_BeginUpdate($h_lv)
    _GUICtrlListView_DeleteAllItems($h_lv)
    For $i = 1 To $a_ini[0][0]
        _GUICtrlListView_AddItem($h_lv, $a_ini[$i][1])
    Next
    _GUICtrlListView_EndUpdate($h_lv)
    Return 1
EndFunc
data.ini contains the exact info you posted above

[conf1]

ID=000001

ID=000002

ID=000003

ID=000004

[conf2]

ID=000005

ID=000006

ID=000007

ID=000008

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

this is closer... works as my first try. But the same(old) problem - the list now adds itselfs...

[.......]

was done before in my project.. But I hope it may be the way to clear first list without deleting (for re-call it later if press button conf1) and creating new ^_^

Oops, my bad.... forgot to clear the LV before re-populating.

This is how it should look:

#include <ListviewConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)

Global $aArray

GUICreate("",200,150)

$LV = GUICtrlCreateListView("Items",10,10,120,120,-1,$LVS_EX_CHECKBOXES)

GUICtrlCreateButton("Conf1",140,10,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")
GUICtrlCreateButton("Conf2",140,40,50,20)
GUICtrlSetOnEvent(-1,"PopulateLV")

GUISetState()
While 1
    Sleep(100)
WEnd

Func PopulateLV()
    
;----- Read different ini sections into array, depending on button pressed -----
    Switch @GUI_CtrlId
        Case 4;Conf1
            $aArray = IniReadSection("data.ini","conf1")
        Case 5;Conf2
            $aArray = IniReadSection("data.ini","conf2")
    EndSwitch
    
;----- populate LV with ini values -----
    _GUICtrlListView_DeleteAllItems($LV)
    For $i = 1 to UBound($aArray) - 1
        GUICtrlCreateListViewItem($aArray[$i][1],$LV)
    Next

EndFunc

...but if Smoke_N's code does the job, stick with that.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
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...