Jump to content

Read Array into GuiCtrlCreateListView()


Recommended Posts

Cannot figure out how to read an entire array into GuiCtrlCreateListView(). So far, all I can do is get one line in at a time.

;this isn't working

$items = GuiCtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1] & "|" & $array[$i][2],$listview)

Far as I know you would have to create a udf to do what you want.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

how about a text file with lines in it like this

line1|1data1|1data2

Line2|2data1|2data2

GuiCtrlCreateListViewItem($text_file,$listview)

ListView doesn't have that capability

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

how about a text file with lines in it like this

line1|1data1|1data2

Line2|2data1|2data2

GuiCtrlCreateListViewItem($text_file,$listview)

You could do something like:

#include <File.au3>

Func _ReadFileIntoListView($s_file, $h_listview)
    Local $aRecords, $x
    _FileReadToArray($s_file, $aRecords)
    If Not _FileReadToArray($s_file,$aRecords) Then
        SetError(1)
        Return 0
    EndIf
    For $x = 1 to $aRecords[0]
        GuiCtrlCreateListViewItem($aRecords[$x],$h_listview)
    Next
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Cannot figure out how to read an entire array into GuiCtrlCreateListView(). So far, all I can do is get one line in at a time.

;this isn't working

$items = GuiCtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1] & "|" & $array[$i][2],$listview)
You understand the items you list are going to be for different COLUMNS, not ROWS. See my example:

#include <GuiConstants.au3>

; 2D array of data
DIM $avData[4][2]
For $r = 0 to 3
    $avData[$r][0] = "Item-" & $r & "-0"
    $avData[$r][1] = "Item-" & $r & "-1"
Next

$Gui_1 = GUICreate("List View Test", 300, 110)
$List_1 = GUICtrlCreateListView("   Column One   |   Column Two   ", 10, 10, 280, 90)

For $r = 0 to 3
    GUICtrlCreateListViewItem($avData[$r][0] & "|" & $avData[$r][1], $List_1)
Next

GUISetState(@SW_SHOW, $Gui_1)

While (1)
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

Each item in the GuiCtrlCreateListView() seperated by "|" is a COLUMN header.

Each instance of GuiCtrlCreateListViewItem() creates one ROW, with multiple items split to the different COLUMNS.

Cheers! :o

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Try that:

#include <file.au3>
#include <GuiConstants.au3>
#include <Array.au3>
$file = "server.txt"
Dim $aRecords
If Not _FileReadToArray($file ,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:")
   Exit
EndIf

GuiCreate("XXXXXX", 200, 430)

$counterOne = 0
$counterOne = $aRecords[0]-1
$listTest = ""
$ListServer = GUICtrlCreateList("", 10, 40, 180, 97, -1)

For $x = 1 to $counterOne
    $listTest = $listTest&"|"& StringStripCR($aRecords[$x])
    GUICtrlSetData(-1, $listTest)
Next

GUISetState(@SW_SHOW)

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

Greetings surfer

Link to comment
Share on other sites

@RandallC...nice UDF. Hopefully the arrary dimensions for my needs will not grow to more than [100][5].

@Sufer...I took your idea of StringStripCR($aRecords[$x]) shortening my code.

Thanks to everyone for the ideas and the help...I'm not too bright when it comes to GUI... coding.

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