Hobbyist

ListView Columns

5 posts in this topic

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:

#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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

change this:

Local $aListView[$iRows][$iCols +4]

to this:

Global $aListView[$iRows][$iCols +4]

It is certainly not best practice to declare globals in functions, but you can work towards that.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Well interestingly enough, after reading your suggestion I return to my code and found I had originally declared $aListView as global but then in the function had used local $aListView.

Long story short - making the recommended change and my correction I still do not get the desire results.

So I am still at a loss. Very perplexed why I can get the second ListView populated by the array but the FileWrite error says it is not an array.

Share this post


Link to post
Share on other sites

Hobbyist,

If I "Populate 1st ListView", press the button to "Populate 2nd ListView", and then "Save to File" all works as I (and I presume you) expect. But any other actions do indeed cause the _FileWriteToArray error - this is because you only fill the $aListView array within the ListView_CreateArray function and that is only called by the "Populate 2nd ListView" button. If you omit that step you do not get an array to pass to the writing function. ;)

You might want to add a check inside the Case $Button14 section to check that you have an array before trying to write it. :)

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

Yes.

Between your observation and @boththose, I cleaned it up, corrected it and now it works.

Thank much to both of you. Being new, I get ahead of myself and myopic on the issue.

Now, my head can stop hurting - HA!

 

Hobbyist

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