Popular Post pixelsearch Posted November 11, 2019 Popular Post Share Posted November 11, 2019 (edited) Hi everybody The script below (901f) allows to wander easily through a listview, selecting any item or subitem by using the 4 direction keys. The Enter key is also managed and allows to fire an event (as double-click does) With the help of mikell (many thanks !) and after several tests based on 1000 rows & 6 columns, we succeeded to code a clear WM_NOTIFY function, which is simple (though solid) and should be reusable without any modification in other scripts dealing with basic listviews (we didn't use or check any particular style for the listview) Trapping the Enter key has been done by using a dummy control + Accelerators, though we spent the whole last week trapping it in another way, using Yashied's Wsp.dll (without any problem) . Finally we choosed the dummy control option... to have a smaller code. Version 901f (Nov 11, 2019) : the pic below shows how the selected subitem appears, with its specific background colour (light blue) Version 901f code : expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 Global $g_iItem = -1, $g_iSubItem = -1 ; item/subitem selected in ListView control Global $idDummy_Dbl_Click = GUICtrlCreateDummy() Global $idDummy_Enter = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]] GUISetAccelerators($aAccelKeys) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idDummy_Dbl_Click MsgBox($MB_TOPMOST, "Double-click activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) Case $idDummy_Enter If _WinAPI_GetFocus() = $hListView And $g_iItem > -1 Then MsgBox($MB_TOPMOST, "Enter activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) EndIf EndSwitch WEnd ;============================================ Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch Case $NM_CLICK, $NM_RCLICK $bMouseDown = False Case $NM_DBLCLK $bMouseDown = False If $g_iItem > -1 Then GUICtrlSendToDummy($idDummy_Dbl_Click) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Version 901k (Dec 16, 2019) What started with a simple "wander through listview" has turned now to a functional CSV file editor, which can be useful to modify your CSV files with AutoIt : Here are the instructions to use the script, based on a CSV file starting like this : street,city,zip,state,beds,baths,sq__ft,type,sale_date,price,latitude,longitude 3526 HIGH ST,SACRAMENTO,95838,CA,2,1,836,Residential,Wed May 21 00:00:00 EDT 2008,59222,38.631913,-121.434879 51 OMAHA CT,SACRAMENTO,95823,CA,3,1,1167,Residential,Wed May 21 00:00:00 EDT 2008,68212,38.478902,-121.431028 ... 1) Import options : comma delimited (default) No need to change anything if your CSV is comma delimited (other options are Semicolon delimited, Tab delimited) 2) Import options : First row = headers (default = checked) * Keep it checked if the 1st row of your imported file contains headers (that's the case in our example) * UNcheck it if the 1st row contains data, making listview headers appear like this : Col 0 | Col 1 | Col 2 ... 3) Import your CSV file : Only now the listview will be created dynamically. As soon as it is populated, GUI becomes resizable/maximizable, which can be helpful during modifications of a listview containing many columns. 4) Selection color : light blue (default) You can change the selected cell background color by clicking the "Selection color" button : this will open Windows color picker. 5) Editing a listview cell : done by Enter key (or double-click), this is how the edited cell will appear : * Please note that the edited background color (green in the pic) depends on each computer theme. It is not related to the selected background we discussed in 4) * Validate your modification with Enter key, or cancel the modification (revert) with Escape Key 6) Edit Font size : 15 (default) 15 was good in the precedent pic, the edited cell had its content "RIO LINDA" perfectly aligned with all other cells (on my computer). Here again, the font height required depends on each computer : if you want the edited font to be bigger (or smaller), just use the updown control. 7) Chained Edit ? (default = No) * "No" => when you finish editing a cell (Enter key), the same cell stays selected. * "Horizontally" => If checked, edition will automatically continue with the cell on its right. * "Vertically" => If checked, edition will automatically continue with the cell below. This feature can be very useful when you modify cells of a whole colum (vertically) or cells by row (horizontally) 8 ) Inserting a blank line (not in Gui) : press the "Ins" key : 9) Deleting a line (not in Gui) : press the "Del" key : 10) Export CSV file : Filename automatically suggested for export will be : Filename import & actual date & actual time, for example : Import name = "Sales Results.csv" => suggested Export name = "Sales Results_2019-12-16 16:00:59.csv" Version 901m (Dec 18, 2019) Yesterday, mikell suggested to import the csv file by dropping it directly into the GUI, good idea This new version 901m allows it. Now there are 2 ways to import the csv file : * Import button * Drag and drop into the large droppable zone, as shown in the pic below (this zone will be reused to create the listview at same coords) Version 901n (Dec 20, 2019) As t0nZ got tons of csv files, pipe "|" separated, here is a new version allowing this 4th separator Version 901p (Dec 25, 2019) New functionality : now you can drag headers to reorder columns. It may help some users who need it while editing their file. Exported CSV file will be saved according to the new columns order. Version 901r (Dec 29, 2019) New functionality : Numeric sort on any column (right click on column header) It is recommended to backup (export) your file before sorting, just in case you need a copy of it, unsorted. Version 901s (Dec 30, 2019) 1 functionality added : String sort (right click on column header) Numeric sort is alright in most cases, but sometimes we also need a String sort like shown in the following picture. Both ways of sorting (numeric and string) are found in this new release. Version 901t (Jan 3, 2020) 3 functionalities added Rename Header , Insert Column , Delete Column (right click on column header to display its context menu) Version 901u (Jan 6, 2020) 1 functionality added : Natural sort. Thanks to jchd for the idea and Melba23 for his function ArrayMultiColSort() included in the script. Though this natural sort isn't fully implemented, it should work when numbers precede letters (see pic below or better, try it on the "street" column found in the downloadable csv test file below) Natural sort duration + listview update are fast, maybe because of the new function _BufferCreate() described here and now added to the script. Version 901w (Jan 10, 2020) Two functionalities added : 1) Close File button, which allows to import other csv file(s) during the same session 2) Import speed has been improved because the listview control is now populated directly by an Array and not anymore by GUICtrlCreateListViewItem() This explains why, in this version, there are no more Control id's for listview items, allowing to empty the listview content in a snap with this line of code : _SendMessage($g_hListView, $LVM_DELETEALLITEMS) That's what it took to add the Close File button and import several csv files during the same session, avoiding id leaks. Please report if any issue is encountered. Version 901x (Jan 14, 2020) One minor functionality added : number of rows is now displayed just under the listview, it may be handy sometimes. Other minor changes included (natural sort speed improved) Credits : Many thanks to Czardas for his function _CSVSplit() and guinness for his function _SaveCSV(), guys you did a great job. Thanks to Musashi : your suggestions and time passed on testing beta versions of the script, that was really helpful and challenging. Not sure I would have ended this script without your detailed reports. Mikell : the 1st step above (901f) that we wrote together, it all started from here. Your knowledge and kindness are legendary ! Not forgetting all other persons who were inspiring : LarsJ, Melba23, jpm, that list could be endless... Download link : version 901x - Jan 14, 2020 (minor update on Jan 15) 901x - CSV file editor.au3 Test csv file (986 rows/12cols) : Sacramento real estate transactions.csv Edited January 15, 2020 by pixelsearch version 901x - Jan 14, 2020 (minor update on Jan 15) t0nZ, Musashi, czardas and 10 others 8 5 Link to comment Share on other sites More sharing options...
Musashi Posted November 12, 2019 Share Posted November 12, 2019 (edited) 21 hours ago, pixelsearch said: ... selecting any item or subitem by using the 4 direction keys Just an info : Currently I am sitting on my old notebook (Win7, AutoIt 3.3.14.0). When I run the script, the Up, Down and Enter keys are working as expected, but Left and Right keys do not. However, I strongly suspect that this has nothing to do with your great script, but is rather due to my laziness to update the notebook to AutoIt 3.3.14.5. EDIT : Thanks to @mikell as well ! Edited November 12, 2019 by Musashi Letraindusoir and pixelsearch 1 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pixelsearch Posted November 12, 2019 Author Share Posted November 12, 2019 (edited) Thanks Musashi Sorry to hear that left & right keys didn't react correctly on your notebook, though I'm not sure it has something to do with AutoIt version. Meanwhile, this is what we are going to do : I'm gonna modify temporarily the script above, so when you will run the script from Scite, it will write in the console the numerical code that appears when you press any key during the script. Please note what value appears when you press the left, then the right key on your notebook, while wandering through the listview Normally here is what appears in the console when you press the 4 direction codes : up (38), down (40), left (37), right (39) . Do you get the same numbers in your console when you run the amended script ? $LVN_KEYDOWN >$iCounter: 1 -->VKey: 38 $LVN_KEYDOWN >$iCounter: 2 -->VKey: 40 $LVN_KEYDOWN >$iCounter: 3 -->VKey: 37 $LVN_KEYDOWN >$iCounter: 4 -->VKey: 39 >Exit code: 0 Time: 44.77 Edited November 13, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 (edited) 1 hour ago, pixelsearch said: Normally here is what appears in the console when you press the 4 direction codes : up (38), down (40), left (37), right (39) . Do you get the same numbers in your console when you run the amended script ? -> I have marked element [Row5/Col2] with the mouse (element is colored) -> ENTER shows Row 5 / Col 2 ==> ok Now I used the keys UP, DOWN, LEFT and RIGHT - this is the result : $LVN_KEYDOWN >$iCounter: 1 -->VKey: 38 $LVN_KEYDOWN >$iCounter: 2 -->VKey: 40 $LVN_KEYDOWN >$iCounter: 3 -->VKey: 37 $LVN_KEYDOWN >$iCounter: 4 -->VKey: 39 (identical to yours) By the way : If this is not a general problem, please don't put too much effort into this . Edited November 13, 2019 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pixelsearch Posted November 13, 2019 Author Share Posted November 13, 2019 (edited) Ok, let's wait and see if another member of the Forum will have the same problem as yours. If I understood correctly, when you press the right or left key, nothing happens (does it mean the same cell stays selected ?) though the console indicates the good values for both keys, that would be really strange... In case I misunderstood, please be kind enough to explain exactly what you meant by "Left and Right keys do not work as expected", does it mean the selection changes to the right cell (if you pressed the right key) or to the left cell (if you pressed the left key), without being coloured ? Edited November 13, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 11 minutes ago, pixelsearch said: If I understood correctly, when you press the right or left key, nothing happens (the same cell stays selected, right ?) Yes ! That's exactly the kind of behavior I meant by "Left and Right keys do not work as expected". "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pixelsearch Posted November 13, 2019 Author Share Posted November 13, 2019 (edited) Ok I added more debug in the script : if I start the way you did, marking cell row 5 / col 2 with the mouse, then key left twice, this is the new debug in the console : $LVN_KEYDOWN >$iCounter: 1 -->VKey: 37 +++Item: 5 +++SubItem: 1 $LVN_KEYDOWN >$iCounter: 2 -->VKey: 37 +++Item: 5 +++SubItem: 0 It means the 1st left key (37) moved the selection to row 5 / column 1 Then the 2nd left key (37) moved the selection to row 5 / column 0 As seen in the pic, on my screen, the selection is really on column 0, but you're saying that on your screen, it is still on column 2, even after you typed 2 left keys. Could you please run the amended script, and share the console results ? Thanks Edited November 13, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 10 minutes ago, pixelsearch said: if I start the way you did, marking cell row 5/ col 2 with the mouse, then key left twice, this is the new debug : This is mine (exactly like yours again) : $LVN_KEYDOWN >$iCounter: 1 -->VKey: 37 +++Item: 5 +++SubItem: 1 $LVN_KEYDOWN >$iCounter: 2 -->VKey: 37 +++Item: 5 +++SubItem: 0 15 minutes ago, pixelsearch said: As seen in the pic, on my screen, the selection is really on column 0, but you're saying that on your screen, it is still on column 2, even after you typed 2 left keys. Yes, Col 2 , although the values look correct - strange. I suggest we wait and see if other members have the same problem. If the problem lies in the outdated AutoIt version (3.3.14.0), then that's the way it is. Of course, it would be nice if a script is downward compatible (at least within 3.3.14.x) but absolute not mandatory. Thank you for your helpfulness, i think it's time for me to go to bed now . Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pixelsearch Posted November 13, 2019 Author Share Posted November 13, 2019 It's soo late and I'm really sleepy too Look, in case it didn't solve your issue, here is a last test : I forced the row to redraw itself after each keystroke with this line of code : _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) Though speed will slow down a bit because of double redraws, let's see if it solves your issue, ok ? Please try the script again, maybe this last test will be the good one, fingers crossed. And if it doesn't solve it... tomorrow will be another day Musashi 1 Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 3 minutes ago, pixelsearch said: And if it doesn't solve it... tomorrow will be another day The true word of a poet 😀 I wish you a good sleep - and me of course as well! "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 6 hours ago, pixelsearch said: ... here is a last test : I forced the row to redraw itself after each keystroke with : _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) [...] _DebugPrint("$LVN_KEYDOWN" & @TAB & ">$iCounter: " & $iCounter & @CRLF & _ "-->VKey: " & $iVK & @CRLF & _ "+++Item:" & @TAB & $g_iItem & @CRLF & _ "+++SubItem:" & @TAB & $g_iSubItem & @CRLF) _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) [...] That solved the problem ! The VKey values in the console output and the graphical representation now match . pixelsearch 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pixelsearch Posted November 13, 2019 Author Share Posted November 13, 2019 (edited) Very happy to hear that Musashi. This is what I just did : * Reverted to the original script in 1st post. * Then added 2 optional lines, changing this : Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 EndIf to that : Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 ; _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 ; _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf As we'll probably never know why this issue appeared at your place (maybe because you're using an old AutoIt version but I'm not sure), so please redownload the original script and uncomment both lines. There's no need to use the debug version, which redraws a whole row no matter what key is pressed, it will slow down the script in case of quick scrolling For the rest of us (until now), as it works with both lines commented, we'll keep them commented. And if tomorrow another user gets the same issue as yours, we'll let him know which lines to uncomment : in my original code they both got this comment ; Musashi needs it for right & left key only Edited November 13, 2019 by pixelsearch Musashi 1 Link to comment Share on other sites More sharing options...
Musashi Posted November 13, 2019 Share Posted November 13, 2019 4 hours ago, pixelsearch said: ... it will slow down the script in case of quick scrolling. For the rest of us (until now), as it works with both lines commented, we'll keep them commented. That would also be my proposal to solve this particular problem. Now everyone knows how to deal with this issue if it occurs. 4 hours ago, pixelsearch said: in my original code they both got this comment ; Musashi needs it for right & left key only 🤣 Thanks again, and mission accomplished. Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Inpho Posted November 14, 2019 Share Posted November 14, 2019 Thanks for the script pixelsearch. This same issue happens to me, but I'm on Windows 7 x64 Pro with latest AutoIt. When pressing left or right arrow keys, nothing happens... until I press up or down. When pressing up or down I notice that my previous left/right press is now actioned on. The edits you made have solved it. On 11/11/2019 at 10:41 PM, pixelsearch said: We'll discuss about the edit code in a future post. Subbed 😛 pixelsearch 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted November 14, 2019 Author Share Posted November 14, 2019 (edited) Thanks Inpho That's nice to report what happened Could you please be kind enough and confirm this : when you use any of the 6 vertical scrolling keys, is the selection correct ? Those 6 keys are : Up key, Down key , Page Up, Page Down, Home (1st row), End (last row) Meanwhile, I'm gonna modify (today done) the original script to take care of this horizontal scrolling issue, depending on the OS of the user. It seems that the structures used in NM_CUSTOMDRAW or LV_ITEM change a bit with the OS, depending on the version of comctl32.dll found in the computer. That's just a guess but Microsoft pages describe this kind of behavior. I wish I knew how to send a CCM_SETVERSION message from AutoIt but I don't know how to do this. Edited November 14, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Musashi Posted November 14, 2019 Share Posted November 14, 2019 21 minutes ago, pixelsearch said: when you use any of the 6 vertical scrolling keys, is the selection correct ? An additional feedback from me (start in [Row5/Col2] again) : Up -> Down -> Page Up -> Page Down -> Home -> End -> and another Up to show the last value. $LVN_KEYDOWN >$iCounter: 1 -->VKey: 38 +++Item: 5 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 2 -->VKey: 40 +++Item: 4 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 3 -->VKey: 33 +++Item: 5 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 4 -->VKey: 34 +++Item: 0 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 5 -->VKey: 36 +++Item: 15 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 6 -->VKey: 35 +++Item: 0 +++SubItem: 2 $LVN_KEYDOWN >$iCounter: 7 -->VKey: 38 +++Item: 99 +++SubItem: 2 +>11:13:50 AutoIt3.exe ended.rc:0 Everything works as expected. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Inpho Posted November 14, 2019 Share Posted November 14, 2019 All 6 keys work correctly; the expected row is selected. Also doesn't suffer from slowdown when holding arrow key; tested on 10,000 x 4 LV. Link to comment Share on other sites More sharing options...
pixelsearch Posted November 14, 2019 Author Share Posted November 14, 2019 (edited) Thanks to both of you for the tests I just made a permanent change in the original script, it should work correctly on any OS, fingers crossed. @Inpho : your sentence "Also doesn't suffer from slowdown when holding arrow key (10,000 rows)" That's the exact reason why I avoid to Redraw if any key is pressed (mikell, if you read this...) It doesn't suffer slowdown because there is no Redraw on any of the 6 vertical keys, only on the 2 horizontal ones (left/right) Edited November 14, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Musashi Posted November 14, 2019 Share Posted November 14, 2019 7 minutes ago, pixelsearch said: ... it should work correctly on any OS, fingers crossed. I jumped wildly through the whole list without any problems . Oh, and you can remove this comment : ; Musashi needs it for right & left key only from your original code now 😛. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Inpho Posted November 14, 2019 Share Posted November 14, 2019 I seem to have forgotten how to use virtual listviews... Tried implementing this into a 3 x 10,000 listview (yes, 3 rows, 10k columns) but I seem to have suffered a brainfart. Could you help with an example of using this in a virtual listview please? My attempt: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> Global $sHeaders = "" Global $aArrayLog[50][10] For $i = 0 To UBound($aArrayLog) - 1 For $ii = 0 To UBound($aArrayLog, 2) - 1 $aArrayLog[$i][$ii] = "kfjdskfsdhfkjsdhfkdshkj" Next Next _ArrayDisplay($aArrayLog) For $i = 0 To UBound($aArrayLog, 2) - 1 $sHeaders &= $i & "|" Next $sHeaders = StringTrimRight($sHeaders, 1) Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500, -1, -1,BitOr($WS_SIZEBOX,$WS_MAXIMIZEBOX,$WS_MINIMIZEBOX) -1) Global $idListView = GUICtrlCreateListView($sHeaders, 15, 60, 430, 400, $LVS_OWNERDATA, BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER,$WS_EX_CLIENTEDGE)) Global $hListView = GuiCtrlGetHandle($idListView) Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 Global $g_iItem = -1, $g_iSubItem = -1 ; item/subitem selected in ListView control Global $idDummy_Dbl_Click = GUICtrlCreateDummy() Global $idDummy_Enter = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $iRows = UBound($aArrayLog) GUICtrlSendMsg( $hListView, $LVM_SETITEMCOUNT, $iRows, 0 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idDummy_Dbl_Click MsgBox($MB_TOPMOST, "Double-click activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) Case $idDummy_Enter If _WinAPI_GetFocus() = $hListView And $g_iItem > -1 Then MsgBox($MB_TOPMOST, "Enter activated cell", _ "Row " & $g_iItem & " / Col " & $g_iSubItem) EndIf EndSwitch WEnd ;============================================ Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local Static $tText = DllStructCreate( "wchar[100]" ) Local Static $pText = DllStructGetPtr( $tText ) Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local $tNMHDR2 = DllStructCreate($tagNMLISTVIEW, $lParam) Local $hWndFrom2 = DllStructGetData($tNMHDR2, "hWndFrom") Local $iCode2 = DllStructGetData($tNMHDR2, "Code") Static $bMouseDown = False Switch $hWndFrom Case $hListView Switch $iCode2 Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $sItem = $aArrayLog[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf EndSwitch Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch ;_GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) Case $NM_CLICK, $NM_RCLICK $bMouseDown = False Case $NM_DBLCLK $bMouseDown = False If $g_iItem > -1 Then GUICtrlSendToDummy($idDummy_Dbl_Click) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY 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