KilRoy Posted May 23, 2006 Share Posted May 23, 2006 I am trying to get a csv to populate a listview, but can't seem to get it right. I have searched and found I can StringSplit into an array, but can't get it to populate the listview. I would post some code, but I've gone through so many iterations that I don't know what was even close to working. It all looks like junk now!! The csv is pretty simple; not many lines and only two columns. I can give you an example of that: input.csv item1,I am 1 item2,I am 2 item3,I am 3 I am trying to learn how to handle arrays, so any help I can get is appreciated. Thanks. KilRoy Link to comment Share on other sites More sharing options...
GaryFrost Posted May 23, 2006 Share Posted May 23, 2006 #include <GUIConstants.au3> Global $lines[3] = ["item1,I am 1", "item2,I am 2", "item3,I am 3"] GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("col1 |col2", 10, 10, 200, 150);,$LVS_SORTDESCENDING) For $x = 0 To UBound($lines) - 1 $line = StringReplace($lines[$x], ",", "|") GUICtrlCreateListViewItem($line, $listview) Next GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() Do $msg = GUIGetMsg() Select Case $msg = $listview MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2) EndSelect Until $msg = $GUI_EVENT_CLOSE 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 More sharing options...
Simucal Posted May 23, 2006 Share Posted May 23, 2006 I had already halfway finished mine when Gafrost swooped in to steal the glory Anyway, here is what I had. #include <file.au3> #include <GUICONSTANTS.au3> Global $a_cvs $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "All (*.*)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_cvs) GUICreate("CVS Listview", 220, 250, -1, -1) $listview = GUICtrlCreateListView("Col1 |Col2 ", 10, 10, 200, 210) GuiSetState() For $i = 1 To UBound($a_cvs) - 1 $s_temp = StringReplace($a_cvs[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next EndIf While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit Pretty much the exact same thing except you browse to the file... and filereadtoarray() it to an array. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
KilRoy Posted May 23, 2006 Author Share Posted May 23, 2006 Thanks a bunch!! Exactly what I was trying to do. Now I need to look at how it works and where I went wrong. Maybe after a few more cups of coffee! Thanks again. KilRoy Link to comment Share on other sites More sharing options...
Gilrim Posted May 26, 2006 Share Posted May 26, 2006 I made a couple of changes to your script, allowing for the csv to have the first line as a comlum-header row, and thus parses *my* csv files much better. Also, I've noticed that excel defaults to ";" as coumnlum seperator, so that's what used here... #include <file.au3> #include <GUICONSTANTS.au3> Global $a_cvs $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_cvs) GUICreate("CVS Listview", 620, 250, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_cvs[1],";","|"), 10, 10, 600, 210) GuiSetState() For $i = 2 To UBound($a_cvs) - 1 $s_temp = StringReplace($a_cvs[$i], ";", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next EndIf While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now