Jump to content

2D-1D array conversion


MyEarth
 Share

Recommended Posts

Hi,

Short story. A listview with column, 01234. The user have the possibility to hide 234. The problem is when a column is hidden the resizing of other column, with mouse i mean, is a problem. Anyway, my idea was move the hidden column at the start, so:

Assuming the initial situation is 01234

User hide column 2, the expected result is 20134

If user hide column 234, the expected result is 23401

If user hide column 3, the expected result is 30124

And so on. I have make a 2D for store the column index and the state ( 1 visible, 0 hidden ) and i need to convert it in 1D array with the expected result for passing to the Listview UDF. Please avoid all the _Array* function for a task like this is a so small array, thanks.

My wrong attempt:

#include <Array.au3>

Local $iCol2 = 1
Local $iCol3 = 0
Local $iCol4 = 1

Local $aResult[5][2] = [[0, 1],[1, 1],[2, $iCol2],[3, $iCol3],[4, $iCol4]]
Local $aFinal[5], $iIndexInc = 0, $iIndexDec = 4
_ArrayDisplay($aResult)

For $i = 0 To UBound($aResult) - 1
    If $aResult[$i][1] = 1 Then
        $aFinal[$iIndexInc] = $aResult[$i][0]
        $iIndexInc += 1
    ElseIf $aResult[$i][1] = 0 Then
        $aFinal[$iIndexDec] = $aResult[$i][0]
        $iIndexDec -= 1
    EndIf
Next

_ArrayDisplay($aFinal)

 

Edited by MyEarth
Link to comment
Share on other sites

  • Moderators

MyEarth,

Sounds complex. Why not just prevent the hidden columns from being resized?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Test", 500, 500)
$cListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3|Column 4", 10, 10, 420, 250)
For $i = 1 To 10
    $sData = ""
    For $j = 0 To 4
        $sData &= Random(0, 10, 1) & "|"
    Next
    GUICtrlCreateListViewItem(StringTrimRight($sData, 1), $cListView)
Next

$cStart = GUICtrlCreateDummy() + 1
For $i = 0 To 4
    GUICtrlCreateCheckbox(" Col " & $i, 10, 300 + (20 * $i), 200, 20)
    GUICtrlSetState(-1, $GUI_CHECKED)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; Check if a checkbox was actioned
            For $i = 0 To 4
                If $iMsg = $cStart + $i Then
                    ; if it was then adjust the column width accordingly
                    If GUICtrlRead($iMsg) = $GUI_CHECKED Then
                        _GUICtrlListView_SetColumnWidth($cListView, $i, 80)
                    Else
                        _GUICtrlListView_SetColumnWidth($cListView, $i, 0)
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Get details of message
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    ; Look for header resize code
    Switch $iCode
        Case $HDN_BEGINTRACKW
            ; Get column
            Local $iCol = DllStructGetData($tStruct, 4)
            ; Prevent resizing if column invisible
            If GUICtrlRead($cStart + $iCol) = $GUI_UNCHECKED Then
                Return True
            EndIf
    EndSwitch

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I have already prevent the hidden column to be resized but the mouse "cursor" remids the column is there, with 0 width, also if you can't resize it. If i move it to the start, this problem doesn't exist anymore. Another attempt:

EDIT: Done

#include <Array.au3>

Local $iCol2 = 0
Local $iCol3 = 1
Local $iCol4 = 0

Local $aResult[5][2] = [[0, 1],[1, 1],[2, $iCol2],[3, $iCol3],[4, $iCol4]]
Local $aFinal[5], $iIndex = 0
_ArrayDisplay($aResult)

For $i = 0 To UBound($aResult) - 1
    If $aResult[$i][1] = 0 Then
        $aFinal[$iIndex] = $aResult[$i][0]
        $aResult[$i][0] = -1
        $iIndex += 1
    EndIf
Next
For $j = 0 To UBound($aResult) - 1
    If $aResult[$j][0] <> -1 Then
        $aFinal[$iIndex] = $aResult[$j][0]
        $iIndex += 1
    EndIf
Next
_ArrayDisplay($aFinal)

 

Edited by MyEarth
Link to comment
Share on other sites

#include <Array.au3>

Local $iCol2 = 0
Local $iCol3 = 1
Local $iCol4 = 0

Local $aResult[5][2] = [[0, 1],[1, 1],[2, $iCol2],[3, $iCol3],[4, $iCol4]]
Local $iNrRow = UBound($aResult)
Local $aFinal[$iNrRow]
Local $aStacks[$iNrRow + 1][2] ; temporary array

_ArrayDisplay($aResult)

For $i = 0 To $iNrRow - 1 ; separates visible and hidden columns
    $aStacks[$aStacks[$iNrRow][$aResult[$i][1]]][$aResult[$i][1]] = $i
    $aStacks[$iNrRow][$aResult[$i][1]] += 1
Next
; _ArrayDisplay($aStacks)

Local $iNDX = 0
; merge again colums appending first hidden then visible
For $x = 0 To 1
    For $i = 1 To $aStacks[$iNrRow][$x]
        $aFinal[$iNDX] = $aStacks[$i - 1][$x]
        $iNDX += 1
    Next
Next

_ArrayDisplay($aFinal)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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