Jump to content

GUI Listview function


Recommended Posts

Hello all,

I need some help with the gui listviewitem function. What I am trying to do is load a file into a listview by a click of a button. But on this GUI I will have a few other buttons that load different files into the listview. I am having problems clearing the listview before I load the other file into the list. I have tried GuictrlDelete function but it was not clearing the listview. Basically in my code I should clear the list before I load the other file into the listview. I also think there is a problem with me loading the file into the listview. Should i have to create another array when loading each item/row into the listview. If anyone can help me with this it would be greatly appreciated, thanks

test13.au3

Link to comment
Share on other sites

Hello all,

I need some help with the gui listviewitem function. What I am trying to do is load a file into a listview by a click of a button. But on this GUI I will have a few other buttons that load different files into the listview. I am having problems clearing the listview before I load the other file into the list. I have tried GuictrlDelete function but it was not clearing the listview. Basically in my code I should clear the list before I load the other file into the listview. I also think there is a problem with me loading the file into the listview. Should i have to create another array when loading each item/row into the listview. If anyone can help me with this it would be greatly appreciated, thanks

At a glance, it appears you are trying to create a new listview item everytime you want to update the listview control. This is not necessary. If the listview item already exists and you just want to update the info inside of it, use GUICtrlSetData(). There is no need to delete the control unless it is no longer needed. If you need to delete the control and it's not deleting, then maybe try hiding the control.. dunno, I've never had that problem, or maybe try deleting the entire listview and re-creating it.

Nomad :D

Link to comment
Share on other sites

Here's a problem I found:

Func BranchCodingGreen() 
if $y = $item1 then 
        Msgbox(0,"Error","You have already clicked this button") 
else 
 $file = FileOpen("C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Green.txt", 0) 
 ; Check if file opened for reading OK 
 If $file = -1 Then 
  MsgBox(0, "Error", "Unable to open file.") 
  Exit 
 EndIf 
 ; Read in lines of text until the EOF is reached 
 While 1 
  $line = FileReadLine($file) 
  If @error = -1 Then ExitLoop 
  $y=StringFormat ("%s",$line) 
  $item1= GUICtrlCreateListViewItem($y,$listview) 
        Wend 
      
        $item1 = $y  ;<<==  you deleted the control ID for the control ;)
            
        FileClose($file) 
EndIf 
EndFunc

Nomad :D

Edited by Nomad
Link to comment
Share on other sites

HI,

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:   Adam McGill
;
; Script Function:
;        Template AutoIt script.
;
; ----------------------------------------------------------------------------
#include <GUIConstants.au3>
#include <GuiListView.au3>
;Global variables used in Service Desk tool
Global $item1, $line
Global $listview, $msg, $x, $y, $z
$item1 = ""
$x = "0"
$y = "0"
$z = "0"
$line = ""
Global $pathBlue = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Blue.txt"
Global $pathGreen = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Green.txt"
Global $pathRed = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Red.txt"


Main()
Func Main()
    GUICreate("Service Desk Tool", 700, 445, 300, 200, -1, $WS_EX_ACCEPTFILES)
    $listview = GUICtrlCreateListView("Branch       |ID Series    |Branch ID   ", 5, 180, 230, 260);,$LVS_SORTDESCENDING)
    
    GUISetBkColor(0x00E0FFFF)  ; will change background color
    
    GUICtrlCreateGroup("Payrolls:", 240, 180, 100, 105)
    $buttonBlue = GUICtrlCreateButton("Blue Payroll", 245, 195, 90, 25)
    $buttonGreen = GUICtrlCreateButton("Green Payroll", 245, 225, 90, 25)
    $buttonRed = GUICtrlCreateButton("Red Payroll", 245, 255, 90, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    
    
    GUISetState()
    
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $buttonBlue
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingBlue()
            Case $msg = $buttonGreen
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingGreen()
            Case $msg = $buttonRed
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingRed()
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
    
EndFunc   ;==>Main


Func BranchCodingBlue()
    If $x = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathBlue, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $x = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($x, $listview)
        WEnd
        
        $item1 = $x
        
        FileClose($file)
    EndIf
    
EndFunc   ;==>BranchCodingBlue


Func BranchCodingGreen()
    If $y = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathGreen, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $y = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($y, $listview)
        WEnd
        
        $item1 = $y
        
        FileClose($file)
    EndIf
EndFunc   ;==>BranchCodingGreen


Func BranchCodingRed()
    If $z = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathRed, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $z = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($z, $listview)
        WEnd
        
        $item1 = $z
        
        FileClose($file)
    EndIf
EndFunc   ;==>BranchCodingRed

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks for the help all, I tried using the #include <GUIListView.au3> but I keep getting error reading file. Is there a certain version I should be using to use this library. I am using version 3.1.1. ?

HI,

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:   Adam McGill
;
; Script Function:
;        Template AutoIt script.
;
; ----------------------------------------------------------------------------
#include <GUIConstants.au3>
#include <GuiListView.au3>
;Global variables used in Service Desk tool
Global $item1, $line
Global $listview, $msg, $x, $y, $z
$item1 = ""
$x = "0"
$y = "0"
$z = "0"
$line = ""
Global $pathBlue = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Blue.txt"
Global $pathGreen = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Green.txt"
Global $pathRed = "C:\Documents and Settings\amcgill\Desktop\SDT\Branch Coding\Branch Coding Red.txt"
Main()
Func Main()
    GUICreate("Service Desk Tool", 700, 445, 300, 200, -1, $WS_EX_ACCEPTFILES)
    $listview = GUICtrlCreateListView("Branch       |ID Series    |Branch ID   ", 5, 180, 230, 260);,$LVS_SORTDESCENDING)
    
    GUISetBkColor(0x00E0FFFF)  ; will change background color
    
    GUICtrlCreateGroup("Payrolls:", 240, 180, 100, 105)
    $buttonBlue = GUICtrlCreateButton("Blue Payroll", 245, 195, 90, 25)
    $buttonGreen = GUICtrlCreateButton("Green Payroll", 245, 225, 90, 25)
    $buttonRed = GUICtrlCreateButton("Red Payroll", 245, 255, 90, 25)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    
    
    GUISetState()
    
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $buttonBlue
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingBlue()
            Case $msg = $buttonGreen
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingGreen()
            Case $msg = $buttonRed
                _GUICtrlListViewDeleteAllItems($listview)
                BranchCodingRed()
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
    
EndFunc   ;==>Main
Func BranchCodingBlue()
    If $x = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathBlue, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $x = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($x, $listview)
        WEnd
        
        $item1 = $x
        
        FileClose($file)
    EndIf
    
EndFunc   ;==>BranchCodingBlue
Func BranchCodingGreen()
    If $y = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathGreen, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $y = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($y, $listview)
        WEnd
        
        $item1 = $y
        
        FileClose($file)
    EndIf
EndFunc   ;==>BranchCodingGreen
Func BranchCodingRed()
    If $z = $item1 Then
        MsgBox(0, "Error", "You have already clicked this button")
    Else
        $file = FileOpen($pathRed, 0)
        ; Check if file opened for reading OK
        If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
        ; Read in lines of text until the EOF is reached
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $z = StringFormat("%s", $line)
            $item1 = GUICtrlCreateListViewItem($z, $listview)
        WEnd
        
        $item1 = $z
        
        FileClose($file)
    EndIf
EndFunc   ;==>BranchCodingRed

So long,

Mega

Link to comment
Share on other sites

Hi,

the code I posted needs beta.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

That still doesn't change the fact that he is storing his control ID in $Item1 when it is created, and then overwriting it with the variable holding the return value of StringFormat("%s", $line). With no control ID it's no wonder that the controls cannot be deleted.

Nomad :D

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