Jump to content

File into list view and other


31290
 Share

Recommended Posts

  • Moderators

31290,

Not very difficult - look for the <<<<<<<<<<<< lines:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>

; Read file into array
$aLines = FileReadToArray("EPES18.txt")

; Deal with title line
$aLines[0] = StringRegExpReplace($aLines[0], "(\x20+)", "|")
; Now the other lines
For $i = 1 To UBound($aLines) - 1
    ; Extract line
    $sLine = $aLines[$i]
    ; Replace tabs with spaces
    $sLine = StringReplace($sLine, @TAB, " ")
    ; Extract possible name field
    $sName = StringRegExpReplace($sLine, "(?U)^.*(\x20.*\x20)(connected|notconnect|err-disabled).*$", "$1")
    ; Convert multiple spaces to singles
    $sStrippedName = StringRegExpReplace($sName, "\x20+", " ")
    ; Set placeholder if no name field
    If $sStrippedName = " " Then $sStrippedName = " ~ "
    ; Replace original name string in line with stripped version - add spaces to ensure multiple spaces before and after
    $sLine = StringReplace($sLine, $sName, " " & $sStrippedName & " ")
    ; Set delimiters by replacing multiple spaces
    $sLine = StringRegExpReplace($sLine, "(\x20{2,19})", "|")
    ; Remove placeholders
    $sLine = StringReplace($sLine, "~", "")
    ; Replace existing line with delimited line
    $aLines[$i] = $sLine

Next

; Read IP Phone ID file
$sID = Fileread("id.txt")

$hGUI = GUICreate("Test", 500, 500)

; Create ListView with first 4 headers plus "IP Phone"
$cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & "|IP Phone", 10, 10, 480, 380)
; Set column widths
For $i = 0 To 4
    _GUICtrlListView_SetColumnWidth($cLV, $i, 90)
Next
; Add content of first 4 fields in each line plus the IP Phone result
For $i = 1 To UBound($aLines) - 1
    ; Assume not IP Phone
    $sIPPhone = "|Not set"
    ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL
    If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then
        ; If found change the set value
        $sIPPhone = "|Set"
    EndIf
    ; Add fields and IP Phone to the ListView
    $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & $sIPPhone, $cLV)
Next

$cDummyCheckRow = GUICtrlCreateDummy() ; Create dummy control <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

; Set sort state
Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummyCheckRow ; Fired by the handler, but only once the handler has exited <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $iRow = GUICtrlRead($cDummyCheckRow) ; Read the row value <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            MsgBox($MB_SYSTEMMODAL, $iRow, StringReplace(_GUICtrlListView_GetItemTextString($cLV, $iRow), "|", @CRLF)) ; Display the row data <<<<<<<<<<<<<<<<<
    EndSwitch
WEnd

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

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode
        Case $LVN_COLUMNCLICK
            ; Get column index
            Local $iCol = DllStructGetData($tStruct, 5)
            If $iCol <> 0 Then
                ; Sort column
                _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol)
            EndIf

        Case $NM_DBLCLK
            $iRow = DllStructGetData($tStruct, 4)
            GUICtrlSendToDummy($cDummyCheckRow, $iRow) ; Send the row value to the dummy control and fire it once returned <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        Case $NM_CUSTOMDRAW
            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
            Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                Case $CDDS_PREPAINT
                    ; Before the paint cycle begins
                    Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
                Case $CDDS_ITEMPREPAINT
                    ; Before painting an item
                    Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations
                Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                    ; Before painting a subitem
                    Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                    Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                    ; Gte text of item
                    $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem)
                    ; Set default back colour
                    $iBkColour = 0xC4C4C4
                    ; Now check for our spoecific items
                    Switch $iSubItem
                        Case 2 ; connection
                            Switch $sText
                                Case "connected"
                                    $iBkColour = 0x00FF00
                                Case "notconnect"
                                    $iBkColour = 0x0000FF
                                Case "err-disabled"
                                    $iBkColour = 0xC4C4C4
                            EndSwitch
                        Case 3 ; vlan
                            Switch $sText
                                Case "trunk"
                                    $iBkColour = 0x00FFFF
                                Case "1"
                                    $iBkColour = 0xFFFF00
                                Case "10"
                                    $iBkColour = 0xC4FFC4
                                Case "13"
                                    $iBkColour = 0xFF00FF
                            EndSwitch
                    EndSwitch
                    ; Set required back colour
                    DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour)
                    Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
            EndSwitch
    EndSwitch

EndFunc   ;==>_WM_NOTIFY

Now you can move the MsgBox around as much as you like.

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

M23, 

Ok, now I understand better the absolute need of a dummy control.

As I said, the msgbox was just a way to check if every variable I need are well gathered. 

For $i = 1 To UBound($aLines) - 1
 Global $sIPPhone = "|Not Set"
    ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL
    If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then
        ; If found change the set value
       Global $sIPPhone = "|Set"
    EndIf
    ; Add fields and IP Phone to the ListView
   Global $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & $sIPPhone, $cLV)
    Next

Global  $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode
        Case $NM_DBLCLK
            Global $iRow = DllStructGetData($tStruct, 4)
            Global $sData = $aLines[$iRow + 1]
            Global $aData = StringSplit($sData, "|")
            If $aData[2] = "" then $aData[2] = "Description not Set"
            Global $aIPPhone = StringTrimLeft($sIPPhone,1)
            ; MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aIPPhone )
            GUISetState(@SW_DISABLE, $hGUI)
            f_PortsOperations()

But this issue is solved, I can now get the proper value if a port is Set or not for IPPhone:

Case 4 ;Ip Phone
                             Switch $sText
                                Case "Set"
                                    $iBkColour = 0x00FA9A
                                    $sIPPhone = "Set"
                                Case "Not Set"
                                    $iBkColour = 0x9370DB
                                    $sIPPhone = "Not Set"
                        EndSwitch

Thanks again for your lights, so much helpful

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

31290,

Glad I could help.

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

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

×
×
  • Create New...