Jump to content

(i) import local file to listview (ii) edit listview (iii) overwrite file


Recommended Posts

This is on my "to do" list but I haven't had time to research self development yet. On that basis (my lack of time so far to look at in detail) any feedback is appreciated but I also appreciate this may just be a placeholder.

I need to do what the title says i.e (i) import local file to listview [it's a lua table format]  (ii) edit the "ID" (per serial number) in the listview then (iii) save the changes to the local file.

The result should be something like the attached png.

Also attached is example of the the local file (which can be 1/upwards serial numbers long).

PS: the topic is based on further development of this https://www.autoitscript.com/forum/topic/167766-listview-select-subitems/?do=findComment&comment=1246546 )

PPS: the local file ("listfile") I import has no extension (and I don't think the lua based application that generates that file would be happy if an extension was added, but not 100% sure)

serial-id-mockup.PNG

listfile

Link to comment
Share on other sites

  • Moderators

newniman,

My GUIListViewEx UDF will allow you to edit the ListView elements - and you can easily read the file into an array for loading and then get an array of the finished version in order to rewrite it. Take a look (the link is in my sig below) and let me know if you have any questions.

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

  • Moderators

newniman,

Rain has stopped play in the Test match, so here is a quick example script using your file. Double click on the "id=#" element to edit it and press the read button to see the array that returned:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include "GuiListViewEx.au3"

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

$cLV = GUICtrlCreateListView("Serial|ID", 10, 10, 480, 200)
_GUICtrlListView_SetColumnWidth($cLV, 0, 300)
_GUICtrlListView_SetColumnWidth($cLV, 1, 75)

$cRead = GUICtrlCreateButton("Read", 10, 400, 80, 30)

GUISetState()

; Read file
$sData = FileRead("listfile")
; Split into array
$aArray = StringRegExp($sData, '((?<=").*(?=")|id=\d+)', 3)
; get into 2D format
Local $aData[UBound($aArray) / 2][2]
For $i = 0 To UBound($aArray) - 1 Step 2
    $aData[$i / 2][0] = $aArray[$i]
    $aData[$i / 2][1] = $aArray[$i + 1]
    GUICtrlCreateListViewItem($aArray[$i] & "|" & $aArray[$i + 1], $cLV)
Next

$iLV_Index = _GUIListViewEx_Init($cLV, $aData, 0, 0, True, 2, "1")

_GUIListViewEx_MsgRegister()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRead

            $aCurrentData = _GUIListViewEx_ReturnArray($iLV_Index)
            _ArrayDisplay($aCurrentData, "Current", Default, 8)
    EndSwitch



    $aRet = _GUIListViewEx_EditOnClick("31")

WEnd

Looks pretty good to me.

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

Rain has stopped play in the Test match

...[]...

Looks pretty good to me.

M23

​It is crazy weather for this time of year - I hear trees could be at risk!

Looks fantastic. I'll work at finishing (e.g id=1 -> 1) later.

Many thanks.

(For my record...include "GUIListViewEx.au3" as per png to run...I have a very poor memory:'()

Include.PNG

Link to comment
Share on other sites

  • Moderators

newniman,

Rather than put your personal includes in with all standard ones why not do as suggested in the Adding UDFs to AutoIt and SciTE tutorial in the Wiki and make your own folder?

M23

 

Edited by Melba23
Forum software foul-up

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

So I made a few changes, probably not too pretty, to delete the "id=" and overwrite file...all works perfectly, thanks:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include "GuiListViewEx.au3"
#include <ButtonConstants.au3>


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

$cLV = GUICtrlCreateListView("Serial|ID", 10, 10, 480, 200)
_GUICtrlListView_SetColumnWidth($cLV, 0, 300)
_GUICtrlListView_SetColumnWidth($cLV, 1, 75)

$cRead = GUICtrlCreateButton("Update listfile with new Serial Number / ID relationship", 10, 300, 120, 50, BitOR($BS_LEFT,$BS_MULTILINE))
GUICtrlSetCursor (-1, 0)

GUISetState()

; Read file
$sData = FileRead("listfile")
; Split into array
$aArray = StringRegExp($sData, '((?<=").*(?=")|id=\d+)', 3)
; get into 2D format
Local $aData[UBound($aArray) / 2][2]

For $i = 0 To UBound($aArray) - 1 Step 2
    $aData[$i / 2][0] = $aArray[$i]
    $aData[$i / 2][1] = StringReplace($aArray[$i + 1], "id=", ""); $aArray[$i + 1]
    ;GUICtrlCreateListViewItem($aArray[$i] & "|" & $aArray[$i + 1], $cLV)
    GUICtrlCreateListViewItem($aData[$i / 2][0] & "|" & $aData[$i / 2][1], $cLV)

Next


$iLV_Index = _GUIListViewEx_Init($cLV, $aData, 0, 0, True, 2, "1")

_GUIListViewEx_MsgRegister()


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cRead
            $aCurrentData = _GUIListViewEx_ReturnArray($iLV_Index)
            ;_ArrayDisplay($aCurrentData, "Current", Default, 8)

;added-below-added-below-added-below-added-below-added-below-added-below-added-below-added-below-added-below-added-below-added

;=>
        Local $aDataOut[UBound($aCurrentData)][2]

        For $i = 0 To UBound($aCurrentData)-1 Step 1
            $aDataOut[$i][0] = "[""" & $aCurrentData[$i][0] & """]"
            $aDataOut[$i][1] = "={id=" & $aCurrentData[$i][1] & ",},"
        Next

        $value = "{" & _ArrayToString($aDataOut,"") & "}"

        $file = FileOpen("listfile", 2)
        FileWrite($file, $value)
        FileClose($file)

;<=
;added-above-added-above-added-above-added-above-added-above-added-above-added-above-added-above-added-above-added-above

    EndSwitch

    $aRet = _GUIListViewEx_EditOnClick("31")

WEnd

My challenge now becomes:

when trying to integrate this code into the full app in which previous code at https://www.autoitscript.com/forum/topic/167766-listview-select-subitems/?do=findComment&comment=1246505 uses GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") [that in relation to selecting an item in another listview], the edit functionality of this listview is no more.

Diabling GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") lets me adapt the listview above ok.

While it makes absolute sense to me why the conflict arises i'm definitely not up to speed on identifying a fix in the short-term.

Any possibility of a code hint? (maybe a bit too involved for that :blink:)  

Link to comment
Share on other sites

  • Moderators

newniman,

Not at all involved - in fact very simple. The problem arises because you can only register 1 function for each message - if you try and register 2 the first is overwritten and no longer works. If you look closely at the GUIListViewEx UDF headers you will see that I have thought of this and actually tell you what to do:

- If the script already has WM_NOTIFY, WM_MOUSEMOVE or WM_LBUTTONUPhandlers then only set unregistered
messages in _GUIListViewEx_MsgRegister and call the relevant _GUIListViewEx_WM_#####_Handler
from within the existing handler

So you need to change the register function to read:

_GUIListViewEx_MsgRegister(False)

so that you do NOT register the WM_NOTIFY message and then add the UDF handler function inside the existing WM_NOTIFY handler:

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    
    Local $tNMHDR, $hWndFrom, $iCode

    

    ; Call the UDF handler inside the existing one
    _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom

Now everything should work as expected - please ask again if not.

M23

P.S. I have been trying for a long time to persuade the powers-that-be to introduce either the ability to register multiple functions to the same message or a standard UDF (several working versions of which exist) allowing this to happen - alas, as yet without success.

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

Apologies for the reply delay in reply Melba23.

From out of the blue a most insidious little bug attacked with result of something i'd never even heard of before "cellulitis" - most unpleasant and very painful :angry:

Anyway, your suggestion works 100% - both the edit and select listboxes are operational. Unfortunately I haven't had time to study your (great) code in detail but do understand the general idea and:  

P.S. I have been trying for a long time to persuade the powers-that-be to introduce either the ability to register multiple functions to the same message or a standard UDF (several working versions of which exist) allowing this to happen - alas, as yet without success.

​I can really understand that frustration.

Thanks.

(I can't yet say i'll not get stuck, a bit, when adding the next listview which, at the current rate, seems inevitable).

Link to comment
Share on other sites

  • Moderators

newniman,

Sorry to hear about your unfortunate malady - I trust you will soon be back to your normal self.

And if you do run into any problems adding the next ListView, you know where to come.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...