Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

ListView Columns

$
0
0

Here's my attempt for the following:

 

Create ListView & populate it

MOVE/drag any column to new position

Create an array from data in ListView

Use the array to populate 2nd ListView, which would show new positions(with column headings)

Take that array to FileWrite the data in the 2nd ListView to a file.

 

I have put in a couple of ArrayDisplays to see what is happening along the way, but they are not important to the concept.

 

I can get the 1st ListView to populate.

I can move the columns around in the 1st ListView

I can create an array from the 1st ListView and populate the 2nd ListView.

 

Problem:

AutoIt         
#include <Array.au3> #include <File.au3> #include <GuiListView.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $main = GUICreate("Column Move - Listview", 680, 515, 150, 100) ;height was 480 $Button12 = GUICtrlCreateButton("Populate 1st ListView", 10, 60, 158, 33) GUICtrlSetState($Button12,$GUI_enABLE) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xE3E3E3) $Button13 = GUICtrlCreateButton("Populate 2nd ListView", 10, 100, 158, 33) GUICtrlSetState($Button13,$GUI_enABLE) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xE3E3E3) $Button14 = GUICtrlCreateButton("Save To File", 10, 140, 158, 33) GUICtrlSetState($Button14,$GUI_enABLE) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0xE3E3E3) $List10 =  GUICtrlCreateListview("",  192, 40, 380, 200);$LVS_EX_HEADERDRAGDROP;,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetExtendedListViewStyle ($List10, $LVS_EX_HEADERDRAGDROP ) _GUICtrlListView_AddColumn($List10, "A0",40) _GUICtrlListView_AddColumn($List10, "B1", 40) _GUICtrlListView_AddColumn($List10, "C2", 40) _GUICtrlListView_AddColumn($List10, "D3", 40) _GUICtrlListView_AddColumn($List10, "E4", 40) _GUICtrlListView_AddColumn($List10, "F5", 40) _GUICtrlListView_AddColumn($List10, "G6", 40) _GUICtrlListView_AddColumn($List10, "H7", 40) $List11 =  GUICtrlCreateListview("",  192,250, 380, 200);$LVS_EX_HEADERDRAGDROP;,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetExtendedListViewStyle ($list11, $LVS_EX_HEADERDRAGDROP ) _GUICtrlListView_AddColumn($List11, "A0",40) _GUICtrlListView_AddColumn($list11, "B1", 40) _GUICtrlListView_AddColumn($List11, "C2", 40) _GUICtrlListView_AddColumn($list11, "D3", 40) _GUICtrlListView_AddColumn($List11, "E4", 40) _GUICtrlListView_AddColumn($list11, "F5", 40) _GUICtrlListView_AddColumn($List11, "G6", 40) _GUICtrlListView_AddColumn($list11, "H7", 40) global  $a_order global $aListView GUISetState(@SW_SHOW) While 1         $iMsg = GUIGetMsg()          Switch $iMsg                     Case $GUI_EVENT_CLOSE                  Exit              case $Button12         ;populate array then populate listview                 local $myarray [6][8]                 for $i = 0 to 5                     ;for $j = 0 to 5                     for $j = 0 to 7                     $myarray [$i][$j] = $i*2+$j                     IF $j >5 Then                         $myarray [$i][$j] = 0                         EndIf                     Next                 next                 _ArrayDisplay($myarray, "populate to see")                 _GUICtrlListView_AddArray($List10,  $myarray)              case $Button13  ;upon clicking this button, expecting to see "new array" reflecting moved columns                  $a_order = _GUICtrlListView_GetColumnOrderArray($List10);                 _ArrayDisplay($a_order,"column array data $List10")                 _GUICtrlListView_SetColumnOrderArray($List10, $a_order)                 _ArrayDelete (  $a_order, 0)                 _GUICtrlListView_CreateArray()                   case $Button14                 _FileWriteFromArray ("C:\ListView\converted "&today()&".csv", $aListView,0,Default,",")                 MsgBox($MB_SYSTEMMODAL, "", "" &@error)          EndSwitch WEnd Func _GUICtrlListView_CreateArray()     ;temp array to register changes in listview after moving columns   Local $iRows = _GUICtrlListView_GetItemCount($list10)    Local $iCols = _GUICtrlListView_GetColumnCount($list10)    Local $aListView[$iRows][$iCols +4]    For $i = 0 To $iRows -1       For $j = 0 To $iCols -1           Local $aItem = _GUICtrlListView_GetItem($list10, $i, $a_order[$j])           $aListView[$i][$j] = $aItem[3]       Next   Next _ArrayDisplay($aListView, "see array of moved columns before pop'g Listview") _GUICtrlListView_AddArray ( $List11, $aListView ); add array called "$aListView" to the second ListView box - $List11 EndFunc Func today() ;Return the current date in mm/dd/yyyy form  Return (@MON & "-" & @MDAY & "-" & @YEAR) EndFunc   ;==>today

When executing the FileWrite From Array, I get error code 2 saying it is not an array.

 

Any ideas on what needs to be corrected, included, eliminate, changed etc would be helpful.

I am relatively new at all this, so the model is probably crude by your standards but its a rough draft just to be sure I can do it.  Thanks.

Hobbyist


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>