GordonFreeman Posted November 15, 2013 Share Posted November 15, 2013 (edited) Hi guys! A help plz. I need make a Listview with "Software Name" + "Link to Download". I want sort ascending. But i will give an option to user edit. I need some ideas. The initial "messy" code is: _UptLV_1(@DesktopDir & "\TEST.txt") Func _UptLV_1($sFile) Local $sCountL = _FileCountLines($sFile) Local $aFileI[$sCountL+1] _FileReadToArray(@DesktopDir & "\" & "TEST.txt",$aFileI) For $i = 1 to UBound($aFileI) Global $aLVInfo[UBound($aFileI)][2]=[["",""]] $Array = StringSplit($aFileI[$i-1], "|") $aLVInfo[$i][0] = $Array[1] $aLVInfo[$i][1] = $Array[2] Next EndFunc ;_UptLV_1() I thought in one text file by columm (easy to do) but it will cause desync when sort. And i cannot see the error in code The text file called "TEST.txt" (Names are only to test/example) Google|www.google.com Yahoo|www.yahoo.com Bing|www.bing.com Gmail|www.gmail.com My logic is fail today :/ Edited November 15, 2013 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 16, 2013 Share Posted November 16, 2013 (edited) This should set $aLVInfo to an array that reads $aLVInfo[$i][0] = Name and $aLVInfo[$i][1] = Site. Now just plug it into your ListView. #include <File.au3> #include <Array.au3> _UptLV_1(@DesktopDir & "\TEST.txt") Func _UptLV_1($sFile) Local $aFileI _FileReadToArray($sFile, $aFileI) ; Creates Array $aFileI Local $aLVInfo[UBound($aFileI)][2] ; Sets $aLVInfo to 2-D Array For $i = 1 to UBound($aFileI) - 1 $Array = StringSplit($aFileI[$i], "|") ; Creates Array of each line from file $aLVInfo[$i][0] = $Array[1] $aLVInfo[$i][1] = $Array[2] Next _ArrayDisplay($aLVInfo) EndFunc ;_UptLV_1() Edited November 16, 2013 by Rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
kylomas Posted November 16, 2013 Share Posted November 16, 2013 GF, You don't need to fart around with splitting and interim arrays and such. Your data is in a format to populate a listview like this... #include <GUIConstantsEx.au3> #include <file.au3> #include <ListviewConstants.au3> local $gui010 = guicreate('Test LV') local $lv010 = guictrlcreatelistview('Software Name|Link to Download',20,20,200,200, -1, _ $LVS_EX_GRIDLINES) guisetstate() _UptLV_1(@DesktopDir & "\TEST.txt") while 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit EndSwitch wend Func _UptLV_1($sFile) local $aFileI _FileReadToArray(@DesktopDir & "\" & "TEST.txt", $aFileI) For $i = 1 To UBound($aFileI) - 1 GUICtrlCreateListViewItem($aFileI[$i],$lv010) Next EndFunc ;==>_UptLV_1 As for editing and sorting, search the forum. There are many examples of both. kylomas 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 Link to comment Share on other sites More sharing options...
GordonFreeman Posted November 16, 2013 Author Share Posted November 16, 2013 A big Thanks to: @Rogue5099 @kylomas You guys really helped me! Frabjous Installation Link to comment Share on other sites More sharing options...
Solution kylomas Posted November 16, 2013 Solution Share Posted November 16, 2013 GF, I figured out how to get this freak to edit cols/sub-cols in place... expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <ListviewConstants.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) Global $hEdit, $Item = -1, $SubItem = 0 local $gui010 = guicreate('Test LV') local $lv010 = guictrlcreatelistview('Software Name|Link to Download',20,20,200,200, $LVS_REPORT, _ $LVS_EX_GRIDLINES) local $hlv010 = GUICtrlGetHandle($lv010) guisetstate() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") _UptLV_1(@DesktopDir & "\TEST.txt") while 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit EndSwitch wend Func _UptLV_1($sFile) local $aFileI _FileReadToArray(@DesktopDir & "\" & "TEST.txt", $aFileI) For $i = 1 To UBound($aFileI) - 1 GUICtrlCreateListViewItem($aFileI[$i],$lv010) Next EndFunc ;==>_UptLV_1 Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hlv010 Switch $iCode Case $NM_DBLCLK Local $aHit = _GUICtrlListView_SubItemHitTest($hlv010) If ($aHit[0] <> -1) Then $Item = $aHit[0] $SubItem = $aHit[1] Local $iSubItemText = _GUICtrlListView_GetItemText($hlv010, $Item, $SubItem) Local $aRect = _GUICtrlListView_GetSubItemRect($hlv010, $Item, $SubItem) if $aHit[1] <> 0 then $hEdit = _GUICtrlEdit_Create($gui010, $iSubItemText, $aRect[0]+25, $aRect[1]+20, $aRect[2] - $aRect[0]-2, 20, $Style) Else local $w = _GUICtrlListView_GetColumnWidth($hlv010,0) $hEdit = _GUICtrlEdit_Create($gui010, $iSubItemText, $aRect[0]+25, $aRect[1]+20, $w, 20, $Style) EndIf _WinAPI_SetFocus($hEdit) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Switch $lParam Case $hEdit Switch $iCode Case $EN_KILLFOCUS Local $iText = _GUICtrlEdit_GetText($hEdit) _GUICtrlListView_SetItemText($hlv010, $Item, $iText, $SubItem) _WinAPI_DestroyWindow($hEdit) $Item = -1 $SubItem = 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc kylomas 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 Link to comment Share on other sites More sharing options...
GordonFreeman Posted November 16, 2013 Author Share Posted November 16, 2013 Really incredible! Thanks for help in my doubt! Frabjous Installation Link to comment Share on other sites More sharing options...
kylomas Posted November 16, 2013 Share Posted November 16, 2013 ...and with a sort... expandcollapse popup#include <GUIConstantsEx.au3> #include <file.au3> #include <ListviewConstants.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT) Global $hEdit, $Item = -1, $SubItem = 0 local $gui010 = guicreate('Test LV') local $lv010 = guictrlcreatelistview('Software Name|Link to Download',20,20,200,200, $LVS_REPORT, _ $LVS_EX_GRIDLINES) local $hlv010 = GUICtrlGetHandle($lv010) guisetstate() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") _UptLV_1(@DesktopDir & "\TEST.txt") while 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit EndSwitch wend Func _UptLV_1($sFile) local $aFileI _FileReadToArray(@DesktopDir & "\" & "TEST.txt", $aFileI) For $i = 1 To UBound($aFileI) - 1 GUICtrlCreateListViewItem($aFileI[$i],$lv010) Next local $aSRT[2] = [false,0] _guictrllistview_simplesort($hlv010,$aSRT,0) EndFunc ;==>_UptLV_1 Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hlv010 Switch $iCode Case $NM_DBLCLK Local $aHit = _GUICtrlListView_SubItemHitTest($hlv010) If ($aHit[0] <> -1) Then $Item = $aHit[0] $SubItem = $aHit[1] Local $iSubItemText = _GUICtrlListView_GetItemText($hlv010, $Item, $SubItem) Local $aRect = _GUICtrlListView_GetSubItemRect($hlv010, $Item, $SubItem) if $aHit[1] <> 0 then $hEdit = _GUICtrlEdit_Create($gui010, $iSubItemText, $aRect[0]+25, $aRect[1]+20, $aRect[2] - $aRect[0]-2, 20, $Style) Else local $w = _GUICtrlListView_GetColumnWidth($hlv010,0) $hEdit = _GUICtrlEdit_Create($gui010, $iSubItemText, $aRect[0]+25, $aRect[1]+20, $w, 20, $Style) EndIf _WinAPI_SetFocus($hEdit) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Switch $lParam Case $hEdit Switch $iCode Case $EN_KILLFOCUS Local $iText = _GUICtrlEdit_GetText($hEdit) _GUICtrlListView_SetItemText($hlv010, $Item, $iText, $SubItem) _WinAPI_DestroyWindow($hEdit) $Item = -1 $SubItem = 0 local $aSRT[2] = [false,0] _guictrllistview_simplesort($hlv010,$aSRT,0) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc 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 Link to comment Share on other sites More sharing options...
AZJIO Posted November 16, 2013 Share Posted November 16, 2013 http://pastebin.com/WhPLnjRN My other projects or all Link to comment Share on other sites More sharing options...
kylomas Posted November 16, 2013 Share Posted November 16, 2013 GF, M23 has a UDF in his sig that has a bunch of listview functionality, including what we just worked on... kylomas 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 Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 16, 2013 Share Posted November 16, 2013 GF, I figured out how to get this freak to edit cols/sub-cols in place...kylomasYou can edit the controls but it doesn't auto save. Wouldn't be a problem just to string search and replace though. What would also be better would be a hyperlink in the GUI. Going straight from file to list view is great since it's already separated withe a "|".Just curious though, could you edit the list view control to be re-sized? My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now