PINTO1927

Add .txt to GUICtrlCreateListView

20 posts in this topic

Hi Guys,

I'm working on this project:

$Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP)
$List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING)
$Item1 = GUICtrlCreateListViewItem("test|test|test", $List)
GUISetState(@SW_SHOW, $GUI)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
   Case $GUI_EVENT_CLOSE, $Exit
      Exit
   Case $Import
      $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)")
      If @error Then ContinueLoop
      GUICtrlSetData($Item1, $Table_Import)

In the text file the fields are delimited with "|" and the values are not in the same row but one below the other.
However in the txt file the sum of the values may change.

Can you help me?

Thank's

Share this post


Link to post
Share on other sites



1 minute ago, PINTO1927 said:

Can you help me?

Help with what? What isn't working yet?

How exactly does that input file look?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

When presented with the import it is only replaced the first item "test" with the imported file directory.
No it is replaced with the content.

Share this post


Link to post
Share on other sites

I'm sorry.

In the text file are present these values, for example:

josh|address|josh@gmail.com
james|address|james@yahoo.com

They must be imported into GUICtrlCreateListView line by line.

Share this post


Link to post
Share on other sites

Ok, that makes sense now. 
So for starters, you are not reading the file at all at the moment. FileOpenDialog retuns the filename, not its content.
You could read the whole file into an Array with _FileReadToArray() and then loop though the records adding them a line at the time with GUICtrlCreateListViewItem()

Making sense? :)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok.
But I would need that of 'importing result remains in the GUI, that's why I was going to use GUICtrlCreateListView.
You have an example to show me?

Share this post


Link to post
Share on other sites

No idea what you mean with the first sentence. Which part of what I described is unclear and do you have questions about? 
You should be able to code it yourself when the process is clear.

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You can not import the text file into GUICtrlCreateListView?

Share this post


Link to post
Share on other sites

No...  as I described: just loop through the records and add them one at the time. What is the issue with that?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok. my question is:
I can use the _FileReadToArray () function, leaving the array table in the GUI and not in the window?

Share this post


Link to post
Share on other sites

We did it by setting this command

$Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP)
$List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING)
$Item1 = GUICtrlCreateListViewItem("test|test|test", $List)
GUISetState(@SW_SHOW, $GUI)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
   Case $GUI_EVENT_CLOSE, $Exit
      Exit
   Case $Import
      $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)")
      If @error Then ContinueLoop
      Local $Array_Lista
      ;============================================================ ADD TO GUICtrlCreateListView
      _FileReadToArray($Tabella_Importa, $Array_Lista)
      $Limite_Array = UBound($Array_Lista) - 1
      For $i = 1 To $Limite_Array
          $All_Box = String($Array_Lista[$i])
          GUICtrlCreateListViewItem($All_Box, $Lista)
      Next

 

Share this post


Link to post
Share on other sites

Is that now working as you want or is there still a question as I don't understand the last question posted?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Last question concerning last posted script.
You can copy the text of a row in GUICtrlCreateListView?

now I can only select rows

Share this post


Link to post
Share on other sites

I managed to obtain import the text file, and I have the result we wanted (see Annex).
Now I would like, if a row is selected, and then pressed the button "Sele", the data "NAME & SURNAME | ADDRESS | EMAIL" is transferred into their inputbox you see on the right.

test.png

Share this post


Link to post
Share on other sites
45 minutes ago, PINTO1927 said:

I managed to obtain import the text file, and I have the result we wanted (see Annex).
Now I would like, if a row is selected, and then pressed the button "Sele", the data "NAME & SURNAME | ADDRESS | EMAIL" is transferred into their inputbox you see on the right.

test.png

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Pinto1927,

This is a demo listview showing how to create a listview and read row values based on the row clicked.  Hope you find it useful.

#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiListView.au3>

Local $Clients = _
        [["1560", "Ben", "Age: 25", "Bla bla...", "Bla bla..."], _
        ["1025", "Somebody", "Age: 14", "Bla bla...", "Bla bla..."], _
        ["9684", "John", "Age: 36", "Bla bla...", "Bla bla..."], _
        ["1002", "Laura", "Age: 15", "Bla bla...", "Bla bla..."], _
        ["1234", "Another guy", "Age: 18", "Bla bla...", "Bla bla..."]]

;Create simple GUI
$Form1 = GUICreate("Select client:", 150, 200)

;Create list of clients
$List_Clients = GUICtrlCreateListView("ID|Name", 10, 10, 130, 200)

; dummy control actioned by notify routine when user clicks on control
$dummy_detail = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; populate listview columns with ID and NAME
For $i = 0 To UBound($Clients) - 1
    _GUICtrlListView_AddItem($List_Clients, $Clients[$i][0])
    _GUICtrlListView_AddSubItem($List_Clients, $i, $Clients[$i][1], 1)
Next

; distribute column widths evenly to show all data
For $i = 0 To _GUICtrlListView_GetColumnCount($List_Clients)
    _GUICtrlListView_SetColumnWidth($List_Clients, $i, $LVSCW_AUTOSIZE_USEHEADER)
Next

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
            ; this control is actioned by the notification routine
        Case $dummy_detail
            _get_client_detail(_GUICtrlListView_GetItemTextString($List_Clients, -1))
    EndSwitch

WEnd

Func _get_client_detail($str)

    $str = StringRegExpReplace($str, '([^\|])\|.*', '$1')

    Local $out
    For $i = 0 To UBound($Clients) - 1
        If $Clients[$i][0] <> $str Then ContinueLoop
        For $j = 0 To UBound($Clients, 2) - 1
            $out &= $Clients[$i][$j] & ' '
        Next
    Next
    MsgBox(0, 'CLIENT DETAIL', $out)

EndFunc   ;==>_get_client_detail

; routine to run when user clicks on any entry in the listview
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    Switch $tNMHDR.IDFrom
        Case $List_Clients
            Switch $tNMHDR.Code
                Case $nm_click
                    GUICtrlSendToDummy($dummy_detail) ; action dummy control in the message loop
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

kylomas

Edited by kylomas
clarification

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hi kylomas, and thanks for the help.
hi kylomas, and thanks for the help.
The problem is that the data inside the GUICtrlCreateListView are imported through a text file, accordingly the time when I try to return this value in a row, brings me 0.
I have created a "Sele" button to simulate the data transfer.

Case $Sele
     $SeleRow = _GUICtrlListView_GetSelectedIndices($List, 0)
     $aItem = _GUICtrlListView_GetItemTextArray($List, 1)
     MsgBox(0, "", $aItem)

With this I try to import the text in the row, but the value is 0.

Something wrong?

Share this post


Link to post
Share on other sites

You're returning an array with the $aItem line, are you reading it as an array or as a simple variable?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Pinto1927,

See if this makes sense...

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

GUICreate("E-Mail", 300, 200)
Local $idSelBtn = GUICtrlCreateButton('Sele', 10, 05, 40, 20)
Local $idListview = GUICtrlCreateListView("Name|Location|Email Address", 10, 30, 280, 180, $LVS_SORTDESCENDING)
_GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER)

; populate listview from text file...columns are "|" delimited

Local $aTextFile = StringSplit(FileRead(@ScriptDir & '\lv.test.txt'), @CRLF, $STR_ENTIRESPLIT)
For $i = 1 To $aTextFile[0]
    If $aTextFile[$i] = '' Then ContinueLoop
    GUICtrlCreateListViewItem($aTextFile[$i], $idListview)
Next

GUISetState(@SW_SHOW)

Local $aIndices, $out

While 1
    Switch GUIGetMsg()
        Case $idSelBtn
            ; get # of listview rows selected
            $aIndices = _GUICtrlListView_GetSelectedIndices($idListview, True)
            $out = ''
            ; loop thru selected indicies and format out
            For $i = 1 To $aIndices[0]
                $out &= _GUICtrlListView_GetItemTextString($idListview, $aIndices[$i]) & @CRLF
            Next
            MsgBox(0, 'Email Selection', $out)
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
WEnd

Input file...lv.test.txt

As BrewmanNH said you are trying to display an array as a simple variable.  If you want to display an array use _arraydisplay($yourarray).

kylomas

edit: same code addressing your other question...

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

GUICreate("E-Mail", 300, 200)
Local $idSelBtn = GUICtrlCreateButton('Sele', 10, 05, 40, 20)
Local $idListview = GUICtrlCreateListView("Name|Location|Email Address", 10, 30, 280, 180, $LVS_SORTDESCENDING)
_GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER)

; populate listview from text file...columns are "|" delimited

Local $aTextFile = StringSplit(FileRead(@ScriptDir & '\lv.test.txt'), @CRLF, $STR_ENTIRESPLIT)
For $i = 1 To $aTextFile[0]
    If $aTextFile[$i] = '' Then ContinueLoop
    GUICtrlCreateListViewItem($aTextFile[$i], $idListview)
Next

GUISetState(@SW_SHOW)

Local $aIndices, $out

While 1
    Switch GUIGetMsg()
        Case $idSelBtn
            ; get # of listview rows selected
            $aIndices = _GUICtrlListView_GetSelectedIndices($idListview, True)
            $out = ''
            ; loop thru selected indicies and format out
            For $i = 1 To $aIndices[0]
                $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],0) & @TAB
                $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],2) & @CRLF
            Next
            MsgBox(0, 'Email Selection', $out)
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
WEnd

 

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

  • Similar Content

    • tezhihi
      By tezhihi
      I have a file (see attached file) with a string all line and this problem on here is I want to separate all $00:, $03:, $10:, $20:, $25:, $30:, $40:, $45:, $110:, $115:, $120: and $T. It's mean that each $ with value start a new line ( a new paragraph). I tried with Regular Expression in notepad++ ex:
      Find ($00:, $01:, $03: and so on) with regex (\$)([0-9]+): and replace is \r\n\1\2 (I think \r\n is @CRLF (not sure :() ) Find $T with regex (\$T)(.*?)(\$T) and replace is \1\2\r\n\3 When I try these regex to replace in notepad on StringRegexReplace the results is incorrect . I have read some example simple about regex. Please advise me how to do that with some example on autoit . The result will be in attached photo. Thanks 
      ahihi.txt

    • PINTO1927
      By PINTO1927
      Hello guys,
      I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing.
      #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StructureConstants.au3> Opt('MustDeclareVars', 1) Global $search_LV, $B_DESCENDING GUICreate("ListView Sort by Column Click", 400, 300) $search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("line4|5|1A", $search_LV) GUICtrlCreateListViewItem("line5|4.50 |1B", $search_LV) GUICtrlCreateListViewItem("line10|4.0 |2C", $search_LV) GUICtrlCreateListViewItem("line3|23|01", $search_LV) GUICtrlCreateListViewItem("line2|0.34560 |09", $search_LV) GUICtrlCreateListViewItem("line1|1.0 |7A", $search_LV) GUICtrlCreateListViewItem("line1|0.1 |8C", $search_LV) GUICtrlCreateListViewItem("line1|97|5B", $search_LV) GUICtrlCreateListViewItem("line1|910|9B", $search_LV) GUICtrlCreateListViewItem("line1|99|11", $search_LV) GUICtrlCreateListViewItem("line1|990.99|06", $search_LV) _GUICtrlListView_SetColumnWidth($search_LV, 0, 75) _GUICtrlListView_SetColumnWidth($search_LV, 1, 75) _GUICtrlListView_SetColumnWidth($search_LV, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ _GUICtrlListView_RegisterSortCallBack($search_LV, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $search_LV ; Kick off the sort callback ;~ _GUICtrlListView_SortItems($search_LV, GUICtrlGetState($search_LV)) ;~ _GUICtrlListView_UnRegisterSortCallBack($search_LV) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $search_LV ;~ If Not IsHWnd($search_LV) Then $hWndListView = GUICtrlGetHandle($search_LV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom ;~ Case $search_LV Case GUICtrlGetHandle($search_LV) Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked ConsoleWrite("Header geklickt" & @CRLF) Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam) _GUICtrlListView_UnRegisterSortCallBack($search_LV) Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If $ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order?
      thank you very much
    • 6401integramandj
      By 6401integramandj
      I am very new to Autoit and pretty new to scripting altogether.I have a PowerShell script that pulls owner info from folders on our file share server. There are 3 owners for every folder, Domain Admin, User setup for network scanning and the user. I am trying to copy the username only from this txt file. I have gotten as far as to being able to read the lines in the txt file but can't seem to read the columns. This is what i have so far.
      #include <File.au3>
      $file = "c:\test01.txt"
      FileOpen($file, 0)
      For $i = 5 to _FileCountLines($file)
          $line = FileReadLine($file, $i)

       msgbox(0,'','the line ' & $i & ' is ' & $line & 'and the column is')
      Next
      FileClose($file)
       
      This is the outcome.....

      This is the txt file

      I am trying to copy the ABC part without the MyDomain\. I know it's line 5 and columns 11-14 of the txt file but i can't figure out how to read it. I hope i'm explaining this correctly. 
    • PINTO1927
      By PINTO1927
      Hello guys, I would have the need to import into the GUICtrlCreateListView all * .txt files in a folder. The * .txt files contain all of the same formatting separated by "|", the script should go on every single file and bring me back the result in the GUICtrlCreateListView. For now I only managed to upload a single file * .txt into the GUICtrlCreateListView with this code:
      Case $Button_Find $File_txt = "\\cond\UPDATE\test.txt" Dim $Array_List _FileReadToArray($File_txt, $Array_List) $Limit_Array = UBound($Array_List) - 1 For $i = 1 To $Limit_Array $All_Box = String($Array_List[$i]) GUICtrlCreateListViewItem($All_Box, $List) Next For $i2 = 0 To _GUICtrlListView_GetColumnCount($List) _GUICtrlListView_SetColumnWidth($List, $i2, $LVSCW_AUTOSIZE_USEHEADER) Next