Sign in to follow this  
Followers 0
crushyna

Error while adding file names to ListView

3 posts in this topic

Hello everyone!

I've encountered a strange problem while adding files (or rather file names) to a ListView.
Mechanics are simple:
1. Select files to add (FileOpenDialog + Multiselect)
2. Split selected string (filepath) into array (StringSplit)
3. File names appear on ListView (GUICtrlCreateListViewItem)

Writing starts from second array (since 0 is array size, and 1 is filepath).
Problem occurs when I try to add one file. Then, no filenames are added.
As far as I know, selecting one file generates only 2 strings (0 and 1) to split, therefore no string is written into ListView.
 

Is there any way / workaround to make this thing work properly?

Some code here:

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

        Case $idAddTest
               $sMessage = "Select test cases to load:"
               $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\data\tests\", "All (*.*)", $FD_FILEMUSTEXIST & $FD_MULTISELECT)
                If @error Then
                MsgBox($MB_SYSTEMMODAL, "", "No test(s) were selected.")
                FileChangeDir(@ScriptDir)
            Else
               FileChangeDir(@ScriptDir)
               $aFileList = StringSplit($sFileOpenDialog, "|", @CRLF)
                    For $i = 2 to $aFileList[0]

                        MsgBox( 0, "test", $aFileList[$i]) ;just for testing purposes

                    GUICtrlCreateListViewItem($aFileList[$i], $idTestCaseList)
                    Next
            EndIf
    EndSwitch
 WEnd

 

And nothing more spectacular from ListView side:

Global $idTestCaseList = GUICtrlCreateListView("List of Tests             ", 24, 24, 225, 502, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
        GUICtrlSetTip(-1, "List of test cases."& @CRLF &"Hold CTRL to select multiple lines.")

 

Any help appreciated!

Share this post


Link to post
Share on other sites



Check for an array after the StringSplit line, and if it's not an array, it's a single file and process accordingly, if it is an array, then continue using the present method.


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
15 hours ago, BrewManNH said:

Check for an array after the StringSplit line, and if it's not an array, it's a single file and process accordingly, if it is an array, then continue using the present method.

Hey!

Took me some time, but I've managed to find magical _PathSplit function :)
That's how it looks right now, and is working properly :)
Thanks for help!
 

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

        Case $idAddTest
               Local $cFilepath
               Local $cFilename
               Local $cDrivepath
               Local $cDirpath
               Local $cExtension
               $sMessage = "Select test cases to load:"
               $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\data\tests\", "All (*.*)", $FD_FILEMUSTEXIST & $FD_MULTISELECT)
                If @error Then
                MsgBox($MB_SYSTEMMODAL, "", "No test(s) were selected.")
                FileChangeDir(@ScriptDir)
            Else
               FileChangeDir(@ScriptDir)
               $aFileList = StringSplit($sFileOpenDialog, "|", @CRLF)
                If $aFileList[0] = 1 Then
                    _PathSplit($aFileList[1], $cDrivepath, $cDirpath, $cFilename, $cExtension)
                    GUICtrlCreateListViewItem($cFilename & $cExtension, $idTestCaseList)
                ElseIf $aFilelist[0] >2 Then
                For $i = 2 to $aFileList[0]

                        MsgBox( 0, "test", $aFileList[$i])

                    GUICtrlCreateListViewItem($aFileList[$i], $idTestCaseList)
                Next
                EndIf
            EndIf
          (...)
     EndSwitch
WEnd

 

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  
Followers 0

  • Similar Content

    • rootx
      By rootx
      How can I change dynamically the background colors of the selected Item? THX
      I try with...
      #include <ListBoxConstants.au3> #include <GuiListBox.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $hListView #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) _GUICtrlListView_SetBkColor($idListview, 0xff0000) _GUICtrlListView_SetTextBkColor($idListview, 0xff0000) _GUICtrlListView_SetTextColor($idListview, 0x0000FF00) $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview) $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview) $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview) $idItem4 = GUICtrlCreateListViewItem("item4|col32|col33", $idListview) $idItem5 = GUICtrlCreateListViewItem("item5|col32|col33", $idListview) $idItem9 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $Index = DllStructGetData($tInfo, "Index") $ctrlID = _GUICtrlListView_GetItemParam($idListview,$Index) Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"), 0) ConsoleWrite($iItemText&@CRLF) _GUICtrlListView_SetTextBkColor($idListview, 0x2E8B57) ;If BitAND(GUICtrlRead($idListview), $GUI_CHECKED) Then ; GUICtrlSetBkColor($ctrlID, 0xff0000) ;Else ; GUICtrlSetBkColor($ctrlID, 0xffff00) ;EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIF  
    • Wingens
      By Wingens
      Hi,
       
      I am trying to create a list view wich shows the content of an ini file. There is a pulldown menu wich allows me to check a certain status in the ini file if the status is found it should read out the key and in every section the same key is located after that it should fill out the listview with all results found.
       
      $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1) GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", 8, 16, 185, 89) GUICtrlCreateLabel("Status:", 32, 40, 37, 17) $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlSetData($STATUS, "Aangevraagd|Verzonden|Afgehandeld", "") GUICtrlCreateGroup("", -99, -99, 1, 1) $View = GUICtrlCreateListView("RMANR|RMANRLEV|DEBITNR|KLANT|STATUS|MODEL|SERIENR|AANGEMELDDOOR|AANMELDDATUM|VERZENDDATUM|RETOURDATUM|KLACHT|OPLOSSING", 8, 120, 1218, 614) $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $EXIT $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?") If $YesOrNo = 6 then GUIDelete($OVERZICHTGUI) MAINMENU() ExitLoop EndIf Case $STATUS $GO = 1 $STATE = GUICtrlRead($STATUS) Local $aArray = IniReadSection(@ScriptDir & "\DB\rma.ini", "STATUS") _ArrayDisplay($aArray, "Gevonden") $FOUNDRMANR = _ArraySearch($aArray, $STATE) MsgBox(4096, "", $FOUNDRMANR) If $FOUNDRMANR = -1 Then MsgBox(4096, "Not Found", "No RMA requests with this status found.") $GO = 0 EndIf If $GO = 1 Then $VAR = IniRead(@ScriptDir & "\DB\rma.ini", "RMANR", $FOUNDRMANR, "Not found") MsgBox(4096, "", $VAR) EndIf EndSwitch WEnd  
      rma-forum.ini
    • Xibalba
      By Xibalba
      Hello again dear forum!
      I want to switch "only text" with "image plus text" in each cell, but can't figure it out.
      #include <GuiConstantsEx.au3> #include <ColorConstants.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) ; GUI Local $StatusBox_Width = 800 Local $StatusBox_Height = 400 Local $hMainGUI = GUICreate("Example", $StatusBox_Width, $StatusBox_Height) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") ; GUI MESSAGE LOOP GUISetState(@SW_SHOW, $hMainGUI) ; LIST VIEW Local $iListView = GUICtrlCreateListView("", 15, 40, 530, 80) _GUICtrlListView_SetExtendedListViewStyle($iListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) ; Load images Local $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($iListView), 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($iListView, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($iListView, "Column 1", 80) _GUICtrlListView_AddColumn($iListView, "Column 2", 80) _GUICtrlListView_AddColumn($iListView, "Column 3", 80) _GUICtrlListView_AddColumn($iListView, "Column 4", 80) _GUICtrlListView_AddColumn($iListView, "Column 5", 80) ; Add items _GUICtrlListView_AddItem($iListView, "One") _GUICtrlListView_AddSubItem($iListView, 0, "", 1, 1) _GUICtrlListView_AddSubItem($iListView, 0, "", 2, 2) GUICtrlCreateListViewItem("1|2|3|4|5", $iListView) MsgBox($MB_SYSTEMMODAL, "Test", "Updating cells...") ; Update cells _GUICtrlListView_SetItem($iListView, "New text", 0, 1) ; OK _GUICtrlListView_SetItem($iListView, "One(1)", 0, 0, 88) ; Here I want to remove the image completely (only way to HIDE image is to put an index that doesn't exist? - 88 in this case) _GUICtrlListView_AddItem($iListView, "Three", 7) ; Here I want to create the text without any image (space) - how? _GUICtrlListView_SetItemImage($iListView, 1, 0, 1) ; OK _GUICtrlListView_SetItemImage($iListView, 0, 1, 2) ; OK While 1 Sleep(100) ; Sleep to reduce CPU usage WEnd Func CLOSEButton() ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ; and @GUI_WinHandle would equal $hMainGUI ;MsgBox(0, "GUI Event", "You selected CLOSE! Exiting...") Exit EndFunc ;==>CLOSEButton Basically, see the comments in the code what I want to accomplish (when clicking OK):
      I want the red box to disappear completely (now bypassed by stating an image index that doesn't exist) I want to create the last row - "Three" - without any image whatsoever. The "OK" comments are the behavior I want to be able to use in certain cases. I'm also puzzled why the value "1" is originally indented while the value "2" is not?!
       
      If it matters, I'm running an older version of AutoIt (v3.3.10.2)
    • rootx
      By rootx
      Holà, I would like to understand why when I select a subitem remains the focus on it. THX
      ;Rootx #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiImageList.au3> #include <MsgBoxConstants.au3> #include <GuiListView.au3> Global $idListview #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 450, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 16, 16, 75, 25) $idListview = GUICtrlCreateListView("", 16, 56, 586, 358, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_AUTOARRANGE), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES)) _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($idListview, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($idListview, 2, "Column 3", 100) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 1) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 3", 2,1) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 2",1, 1) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 3",2, 1) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iCol = DllStructGetData($tInfo, "SubItem") ConsoleWrite("Column clicked: " & $iCol & @CRLF) Case $NM_CLICK $aHit = _GUICtrlListView_SubItemHitTest($hWndFrom) $LVEIP_Item = $aHit[0] $LVEIP_SubItem = $aHit[1] Local $tItem $tItem = DllStructCreate($tagLVITEM) DllStructSetData($tItem, "Mask", $LVIF_STATE) DllStructSetData($tItem, "Item", $LVEIP_Item) DllStructSetData($tItem, "SubItem", $LVEIP_SubItem) DllStructSetData($tItem, "State", $LVIS_SELECTED) DllStructSetData($tItem, "StateMask", $LVIS_SELECTED) _GUICtrlListView_SetItemEx($hWndFrom, $tItem) ConsoleWrite("Selected Cell " & _GUICtrlListView_GetItemText($idListview,$LVEIP_Item,$LVEIP_SubItem)&@CRLF) EndSwitch EndSwitch EndFunc  
    • david1337
      By david1337
      Hey guys
      This may be quite simple, but I haven't manage to solve it yet :/
      All I want to do is get the ID of Xitem, so I can click it with " _GUICtrlListView_ClickItem" .
      So I need to find the item based on the that fact that I know the text/string name of that item.
       
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Example() Func Example() GUICreate("listview items", 300, 300, -1, -1) Local $idListview = GUICtrlCreateListView("col1", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) Local $idButton = GUICtrlCreateButton("ID_of_Xitem?", 75, 170, 70, 20) Local $idItem1 = GUICtrlCreateListViewItem("Aitem", $idListview) Local $idItem2 = GUICtrlCreateListViewItem("Xitem", $idListview) Local $idItem3 = GUICtrlCreateListViewItem("Zitem", $idListview) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox(0,"","ID of Xitem is ?") _GUICtrlListView_ClickItem($clv, ?) EndSwitch WEnd EndFunc ;==>Example