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
      Listview subitem persistent focus?
      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
      Find ID of Listview item by stringname
      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  
    • skybax
      Array to Listview
      By skybax
      Good morning all,
      I have a question regarding a situation im in...
       
      I have an array with information from sql query, how can i send this information to a listview ?
       
      $citeste_daune = "SELECT `id_dauna`,`data_incident`,`sala`,`autor`,`suma` FROM `daune` WHERE `status`=1;" $sa_citit_daune = _query($sqlinstance, $citeste_daune) Global $aresult[10001][5] = [[10000, 5]] Global $iindex = 0 With $sa_citit_daune While NOT .eof $aresult[$iindex][0] = .fields("id_dauna").value $aresult[$iindex][1] = .fields("data_incident").value $aresult[$iindex][2] = .fields("sala").value $aresult[$iindex][3] = .fields("autor").value $aresult[$iindex][4] = .fields("suma").value $iindex = $iindex + 1 .movenext WEnd EndWith ReDim $aresult[$iindex][5] $aresult[0][0] = $iindex - 1 _ArrayDisplay($aresult) GUICtrlCreateListViewItem(_ArrayToString($aresult), $lista_daune_active)  
      This is what i see when i execure _ArrayDisplay($aresult)

    • Trolleule
      Show ToolTip when hovering over listview group
      By Trolleule
      Hi,
      i want to display a tooltip when i hover over the listview group. It sounds not difficult but i couldn't find a solution and i searched for autoit as well as for c# :/
      So i came up with a not so pretty solution:
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <GuiToolTip.au3> #include <WinAPI.au3> Global $idListview, $hWndListView Global $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip Global Const $LVN_GROUPINFO = ($LVN_FIRST - 88) Global Const $tagNMLVGROUP = $tagNMHDR & ";int iGroupId;uint iNewState;uint iOldState" ; $LVGS_flags $LVGS_flags Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tInfo, $tNMHDR = DllStructCreate($tagNMHDR, $lParam), $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom"), $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode ; Case $of?????? ; A Group was clicked <---- I need help with this Case $LVN_GROUPINFO ConsoleWrite("hier" & @CRLF) $tInfo = DllStructCreate($tagNMLVGROUP, $lParam) _DebugPrint("$LVN_GROUPINFO" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->GroupId:" & @TAB & DllStructGetData($tInfo, "iGroupId") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "iNewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "iOldState")) Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->Param:" & @TAB & DllStructGetData($tInfo, "Param")) ; No return value Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint If Not StringInStr($CmdLineRaw, "/ErrorStdOut") Then Exit MsgBox($MB_TOPMOST, @ScriptName, 'please run from the editor, thanks', 10) Example() Func Example() Local $aInfo, $hImage, $idListview $ghui = GUICreate("ListView Group COLLAPSIBLE", 400, 300) $idListview = GUICtrlCreateListView("", 30, 20, 354, 218);, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_REPORT, $WS_CLIPSIBLINGS)) $hWndListView = GUICtrlGetHandle($idListview) ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($idListview, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($idListview, "Column 1", 100) _GUICtrlListView_AddColumn($idListview, "Column 2", 100) _GUICtrlListView_AddColumn($idListview, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2) ; Build groups _GUICtrlListView_EnableGroupView($idListview) _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1", 1) ;~ _GUICtrlListView_SetGroupInfo($idListview, 1, "Group 1", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <--- _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2") ;~ _GUICtrlListView_SetGroupInfo($idListview, 2, "Group 2", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <--- _GUICtrlListView_SetItemGroupID($idListview, 0, 1) _GUICtrlListView_SetItemGroupID($idListview, 1, 2) _GUICtrlListView_SetItemGroupID($idListview, 2, 2) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Local $apos = _GUICtrlListView_GetGroupRect($idListview, 2, $LVGGR_LABEL) Local $test = GUICtrlCreateLabel("a", 2, 2, 10, 17) Local $val = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_STYLE) Local $valex = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_EXSTYLE) Local $aha = _WinAPI_CreateWindowEx($valex+$WS_EX_LAYERED, "static", "blabla", $val, $apos[0], $apos[1], 50, 20, $hWndListView) _GUIToolTip_AddTool($hToolTip, $hWndListView, "This is a ToolTip3", $aha) GUISetState(@SW_SHOW) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Short description: I only created a label with CreateWindowEx which i can append to the listview control and layered it with the $WS_EX_Layered flag so it looks like it's transparent. Then i only added a tooltip tool to that created label.
      Hover over the Group 2 text and the Tooltip will be displayed. My question is: does someone know another perhaps much prettier solution?
      Thanks in advance
    • Stacker
      Context menu
      By Stacker
      Hi all,
      i need to enable/disable an item($listitem3) on context menu if find a specific value in listview ($idlistview).The item start disable (see code)
      I use GUIGetMsg() in my code
       
      $listtxt = GUICtrlCreateContextMenu($idListView) $listitem1 = GUICtrlCreateMenuItem("Ignore", $idListView) $listitem2 = GUICtrlCreateMenuItem("Remove Ignore", $idListView) $listitem3 = GUICtrlCreateMenuItem("Provide", $idListView) GUICtrlSetState(-1,$GUI_disable) Any suggestion ?
      Thanks