Jump to content
Sign in to follow this  
PINTO1927

Add .txt to GUICtrlCreateListView

Recommended Posts

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


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  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


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  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 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

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

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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Kiko745
      Hello!
      I am new to autoit so please if someone could help me. I am trying to combine multiple .txt files but I can't get it right. In every file are the exact amout of lines ( for example here are 2 ) ,            I don't want to make it for just 2 lines for each txt files but for all the lines the txt files contains. The thing I want to do is :
      Text File 1
      Hello my name
      I am a big
      ...
      Text File 2
      is Fred,
      Potato head for
      ...
      Text File 3
      and I like to eat pizza.
      Not getting this right.
      ...
      ------------------- Combine them all into one txt file like here ------------------------------
      Final Text file
      Hello my name is Fred, and I like to eat pizza.
      I am a big Potato head for Not getting this right.
      ...
       
      Thanks for any advice!
      P.S. Sorry for my English, not my first language.
       
    • By ThePoro
      Hello,
      I have a problem with getting first 10 characters with a big txt file, about 50k lines. I only want 10 characters of each line and save it into another file. I tried to use Stringleft every line and save it into another file but it was really slow to do it. I tried to save it into a variation like $var=$var&stringleft($file,10)&@CRLF. It's faster but still really slow.
      Can anybody help me with this
      Thank you so much
    • By Skysnake
      I thought I remembered this from somewhere, then I searched, but cannot find which I am looking for...
      How to display additional, hidden ListViewItem text in a popup?
      I thought I saw a Style element that does that, but I cannot find it
      Just point me in the right direction please?
    • By kneze
      hi
      i use from Command Line net user /Domain UserID >> C:\temp\sample.txt to request informations about specific Domain User. Now i wil get Password last set, Password expires, password changeable and all Groups from Global Group Membership of this User to display in a MsgBox. With FUNC _readGroups i can check which position is group date of last password set but i don't know how to get needed informations as i wrote at the beginning.
      Thanks in advance for any hint how can i solve it.
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.3 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <File.au3> $FilePath=@ScriptDir &"\sample.txt" $StringToSearch="Password last set" $CaseSense=0 $Lines=_FileCountLines($FilePath) $hFile=FileOpen($FilePath,0) $LinesCount=_FileCountLines($FilePath) For $i=0 To Number($Lines) $Test=FileReadLine($hFile,$i) If StringInStr($Test,$StringToSearch,$CaseSense) Then $foundLine = $i _readGroups($foundLine,$LinesCount,$i) ;MsgBox(0,"","The string " & $StringToSearch & " was found on line " & $i) ;MsgBox(0,"","Lines found: " & $LinesCount) ExitLoop EndIf Next FileClose($hFile) FUNC _readGroups($foundLine,$LinesCount,$i) ;For $j=$foundLine To Number($LinesCount) $lLine=FileReadLine($hFile,$i) ;$split = StringSplit($lLine," ") $split = StringSplit(StringStripWS($lLine,1)," ") For $x = 1 To $split[0] MsgBox(0,$x,$split[$x]) Next ;MsgBox(0,"",$split[15]& " " & $split[16]) ;Next EndFunc  
      sample.txt
    • 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

×
×
  • Create New...