Zedna Posted August 11, 2014 Share Posted August 11, 2014 (edited) I have ListView in report mode. I want to achieve two things 1) no selection 2) only select subitem and not whole row (now it uses $LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES) I have dirty workaround for "1) no selection" here by deselecting all rows after click/doubleclick but I want to know if there is better more effective solution ... expandcollapse popup#AutoIt3Wrapper_UseX64=n #NoTrayIcon #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> Global Const $WM_LV_CLICK = $WM_USER + 1 Global Const $WM_LV_DBLCLK = $WM_USER + 2 $Form1 = GUICreate("ListView test", 300, 200) $ListView1 = GUICtrlCreateListView('Col1|Col2|Col3', 2, 2, 296, 196) _GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES)) GUISetState(@SW_SHOW) GUICtrlCreateListViewItem ( "R1C1|R1C2|R1C3", $ListView1) GUICtrlCreateListViewItem ( "R2C1|R2C2|R2C3", $ListView1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_LV_CLICK, "WM_LV_CLICK") ; WM_USER GUIRegisterMsg($WM_LV_DBLCLK, "WM_LV_DBLCLK") ; WM_USER While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode Local $tCustDraw, $iDrawStage, $hDC Local $iColor, $iItem, $iSubItem, $text $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") If $hWnd = $Form1 Then $NMHDR = DllStructCreate($tagNMHDR , $lParam) $event = DllStructGetData($NMHDR, 'Code') If $wParam = $ListView1 And $event = $NM_CLICK Then $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) $item = DllStructGetData($NMLISTVIEW, 'Item') $subitem = DllStructGetData($NMLISTVIEW, 'SubItem') _SendMessage($Form1, $WM_LV_CLICK, $item, $subitem) EndIf If $wParam = $ListView1 And $event = $NM_DBLCLK Then $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) $item = DllStructGetData($NMLISTVIEW, 'Item') $subitem = DllStructGetData($NMLISTVIEW, 'SubItem') _SendMessage($Form1, $WM_LV_DBLCLK, $item, $subitem) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_LV_CLICK($hWnd, $MsgID, $wParam, $lParam) _GUICtrlListView_SetItemSelected($ListView1, -1, False) EndFunc Func WM_LV_DBLCLK($hWnd, $MsgID, $wParam, $lParam) _GUICtrlListView_SetItemSelected($ListView1, -1, False) EndFuncEDIT: Added: #include <WindowsConstants.au3> Edited September 22, 2014 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 11, 2014 Author Share Posted August 11, 2014 Here is some related topic '?do=embed' frameborder='0' data-embedContent>> Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
iahngy Posted September 21, 2014 Share Posted September 21, 2014 Zedna, it errs at $WM_USER , var not found. Link to comment Share on other sites More sharing options...
Zedna Posted September 22, 2014 Author Share Posted September 22, 2014 Sorry. Add this line to the includes: #include <WindowsConstants.au3> I use changed #include <GUIConstants.au3> which contains ALL include files so I don't need to find which include file is needed every time. Because I use Obfuscator /StripOnly I have no problem with compiled EXE size. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted September 22, 2014 Author Share Posted September 22, 2014 Here is nice script doing ListView not clickable = no selection Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Solution LarsJ Posted September 22, 2014 Solution Share Posted September 22, 2014 Zedna, May be you can use something like this:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> Opt( "MustDeclareVars", 1 ) Global $hGui, $hLV, $aHit[2] = [ -1, -1 ] ; $aHit contains row & col of marked cell MainFunc() Func MainFunc() $hGui = GUICreate( "Mark Cell in Listview", 250, 222 ) Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 250-4, 222-4 ) $hLV = ControlGetHandle( $hGui, "", $idLV ) For $i = 0 To 49 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV ) Next GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_ITEMCHANGED Local $tNMLISTVIEW, $iItem, $aInfo $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam ) $iItem = DllStructGetData( $tNMLISTVIEW, "Item" ) _GUICtrlListView_SetItemSelected( $hLV, $iItem, False ) Local $aInfo = GUIGetCursorInfo( $hGui ) If $aInfo[2] Then $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-2, $aInfo[1]-2 ) ; Upper left = ( 2, 2 ) If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then If $aHit[0] > -1 Then _ _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] ) If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then $aHit[0] = $aInfo[0] ; Row $aHit[1] = $aInfo[1] ; Col Else $aHit[0] = -1 ; Row $aHit[1] = -1 ; Col EndIf _GUICtrlListView_RedrawItems( $hLV, $iItem, $iItem ) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem Local $dwItemSpec = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index Local $iSubItem = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem" ) ; Subitem index Local $uItemState = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" ) ; Item state If $dwItemSpec = $aHit[0] Then ; Marked row Switch $iSubItem Case $aHit[1] ; Marked column DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR Case Else ; Other columns DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) ; Forecolor black DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) ; Backcolor white EndSwitch Else ; Other rows DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Zedna and Hawkysoft 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Zedna Posted September 23, 2014 Author Share Posted September 23, 2014 @LarsJ That's perfect!! Very nice. Thank you for that example There is still very little cosmetic "bug" with painting focus rectangle of whole row (FullRowSelect) but this your example is the best solution I have ever seen. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
LarsJ Posted September 23, 2014 Share Posted September 23, 2014 To remove the dotted border around the focused item, just add this command_GUICtrlListView_SetItemState( $hLV, $iItem, 0, $LVIS_FOCUSED )immediately after this line:_GUICtrlListView_SetItemSelected( $hLV, $iItem, False ) Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 23, 2014 Moderators Share Posted September 23, 2014 LarsJ,Excellent script. I have been looking into how to do that for a long time - thanks for providing such a clean solution. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted September 23, 2014 Author Share Posted September 23, 2014 (edited) @LarsJ Absolutely perfect solution! Thanks. Marked as solved. :thumbsup: Edited September 23, 2014 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
iahngy Posted September 26, 2014 Share Posted September 26, 2014 (edited) Thank you very much Zedna and Larsj; the code comes in handy just in time for my little code at work. Mine at work is to display a table where i can click on any cell of listview and it paste info to another window. The highlight on subitems is so awesome. Edited September 26, 2014 by iahngy Link to comment Share on other sites More sharing options...
iahngy Posted September 26, 2014 Share Posted September 26, 2014 To get text of the subitems/items clicked on, i just add this line? It working for me. $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-2, $aInfo[1]-2 ) ; Upper left = ( 2, 2 ) ConsoleWrite(_GUICtrlListView_GetItemText($hLV, $aInfo[0], $aInfo[1]) &" item text" &@crlf) Link to comment Share on other sites More sharing options...
iahngy Posted September 26, 2014 Share Posted September 26, 2014 (edited) Hi Larsj, The listview window size depends on the main gui window ..Can the listview window size is smaller instead of being smaller only by 4 , can be any number? GUICtrlCreateTab) $hGui = GUICreate( "Mark Cell in Listview", 250, 222 ) Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 250-4, 222-4 ) Edited September 26, 2014 by iahngy Link to comment Share on other sites More sharing options...
LarsJ Posted September 26, 2014 Share Posted September 26, 2014 Good point about the position and size. This should be better:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> Opt( "MustDeclareVars", 1 ) Global $hGui, $hLV, $iLVx, $iLVy, $aHit[2] = [ -1, -1 ] ; $aHit contains row & col of marked cell Example() Func Example() $hGui = GUICreate( "Mark Cell in Listview", 350, 350, -1, -1, BitXOR( $WS_OVERLAPPEDWINDOW, $WS_MAXIMIZEBOX ) ) Local $idButton = GUICtrlCreateButton( "Text", 10, 10, 150, 25 ) GUICtrlSetResizing( $idButton, $GUI_DOCKALL ) $iLVx = 50 $iLVy = 50 Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", $iLVx, $iLVy, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV ) Next $hLV = GUICtrlGetHandle( $idLV ) _GUICtrlListView_SetColumnWidth( $hLV, 0, ( 250 - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 1, ( 250 - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 2, ( 250 - 20 ) * 0.30 ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUIRegisterMsg( $WM_SIZING, "WM_SIZING" ) GUISetState() While 1 Switch GUIGetMsg() Case $idButton Local $sTxt = $aHit[0] = -1 ? "No cell selected" : _ _GUICtrlListView_GetItemText( $hLV, $aHit[0], $aHit[1] ) MsgBox( 0, "", $sTxt ) Case $GUI_EVENT_RESIZED ; LV screen position Local $aPos = WinGetPos( $hLV ) Local $tPoint = DllStructCreate( "int X;int Y" ) DllStructSetData( $tPoint, "X", $aPos[0] ) DllStructSetData( $tPoint, "Y", $aPos[1] ) _WinAPI_ScreenToClient( $hGui, $tPoint ) $iLVx = DllStructGetData( $tPoint, "X" ) $iLVy = DllStructGetData( $tPoint, "Y" ) ; Column widths _GUICtrlListView_SetColumnWidth( $hLV, 0, ( $aPos[2] - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 1, ( $aPos[2] - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 2, ( $aPos[2] - 20 ) * 0.30 ) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_ITEMCHANGED Local $tNMLISTVIEW, $iItem, $aInfo $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam ) $iItem = DllStructGetData( $tNMLISTVIEW, "Item" ) _GUICtrlListView_SetItemSelected( $hLV, $iItem, False ) _GUICtrlListView_SetItemState( $hLV, $iItem, 0, $LVIS_FOCUSED ) Local $aInfo = GUIGetCursorInfo( $hGui ) If $aInfo[2] Then $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-$iLVx, $aInfo[1]-$iLVy ) If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then If $aHit[0] > -1 Then _ _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] ) If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then $aHit[0] = $aInfo[0] ; Row $aHit[1] = $aInfo[1] ; Col Else $aHit[0] = -1 ; Row $aHit[1] = -1 ; Col EndIf _GUICtrlListView_RedrawItems( $hLV, $iItem, $iItem ) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem Local $dwItemSpec = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index Local $iSubItem = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem" ) ; Subitem index Local $uItemState = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" ) ; Item state If $dwItemSpec = $aHit[0] Then ; Marked row Switch $iSubItem Case $aHit[1] ; Marked column DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR Case Else ; Other columns DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) ; Forecolor black DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) ; Backcolor white EndSwitch Else ; Other rows DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_SIZING( $hWnd, $Msg, $wParam, $lParam ) Local $aPos = WinGetPos( $hLV ) _GUICtrlListView_SetColumnWidth( $hLV, 0, ( $aPos[2] - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 1, ( $aPos[2] - 20 ) * 0.30 ) _GUICtrlListView_SetColumnWidth( $hLV, 2, ( $aPos[2] - 20 ) * 0.30 ) EndFunc robertocm 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
iahngy Posted September 27, 2014 Share Posted September 27, 2014 (edited) Hi LarsJ Thank you very much. I am really appreciated. The LV with hilights doesnt work on the tabs ( it works on tab1 so far but not on more like if i wnt another list on tab2 .. ..is it possible to make lv items higlighted on tabs ( GUICtrlCreateTab, GUICtrlCreateTabItem ) ? I moved $text = _GUICtrlListView_GetItemText($hLV, $aInfo[0], $aInfo[1]) to beneath this line in the function Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) ( and it still work with highlight and display text ) $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-$iLVx, $aInfo[1]-$iLVy ) ( so i dont have to use button to get text and when any highlited it gives text the same time) I finally figured out how to clear the listview to load another array/table/excel on the listview. _GUICtrlListView_DeleteAllItems($idLV) do $cc = _GUICtrlListView_GetColumnCount($idLV) ConsoleWrite($cc &" colums" &@crlf) for $i = 0 to $cc _GUICtrlListView_DeleteColumn ( $idLV, $i) Next Until $cc = 0 Edited September 27, 2014 by iahngy Link to comment Share on other sites More sharing options...
LarsJ Posted September 29, 2014 Share Posted September 29, 2014 Listviews on tab items:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> Opt( "MustDeclareVars", 1 ) Global $hGui, $hLV, $iLVx, $iLVy, $aHit[2] = [ -1, -1 ] ; $aHit contains row & col of marked cell Global $aLV = [ [ 0, 25, 45, -1, -1 ], _ ; $hLV, $iLVx, $iLVy, $aHit[0], $aHit[1] [ 0, 125, 145, -1, -1 ], _ [ 0, 225, 245, -1, -1 ] ] Example() Func Example() $hGui = GUICreate( "Mark Cell in Listview", 500, 520 ) Local $idTab = GUICtrlCreateTab( 10, 10, 480, 500 ) GUICtrlCreateTabItem( "Tab 0, LV 0" ) Local $idLV0 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 25, 45, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV0 ) Next $hLV = GUICtrlGetHandle( $idLV0 ) $aLV[0][0] = $hLV $iLVx = 25 $iLVy = 45 GUICtrlCreateTabItem( "Tab 1, LV 1" ) Local $idLV1 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 125, 145, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV1 ) Next $aLV[1][0] = GUICtrlGetHandle( $idLV1 ) GUICtrlCreateTabItem( "Tab 2, LV 2" ) Local $idLV2 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 225, 245, 250, 250 ) For $i = 0 To 99 GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV2 ) Next $aLV[2][0] = GUICtrlGetHandle( $idLV2 ) GUICtrlCreateTabItem( "" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState() Local $iTab, $iTabPrev = 0 While 1 Switch GUIGetMsg() Case $idTab $iTab = GUICtrlRead( $idTab ) $aLV[$iTabPrev][3] = $aHit[0] $aLV[$iTabPrev][4] = $aHit[1] $hLV = $aLV[$iTab][0] $iLVx = $aLV[$iTab][1] $iLVy = $aLV[$iTab][2] $aHit[0] = $aLV[$iTab][3] $aHit[1] = $aLV[$iTab][4] If $aHit[0] <> -1 Then _ _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] ) $iTabPrev = $iTab Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_ITEMCHANGED Local $tNMLISTVIEW, $iItem, $aInfo $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam ) $iItem = DllStructGetData( $tNMLISTVIEW, "Item" ) _GUICtrlListView_SetItemSelected( $hLV, $iItem, False ) _GUICtrlListView_SetItemState( $hLV, $iItem, 0, $LVIS_FOCUSED ) Local $aInfo = GUIGetCursorInfo( $hGui ) If $aInfo[2] Then $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-$iLVx, $aInfo[1]-$iLVy ) If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then If $aHit[0] > -1 Then _ _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] ) If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then $aHit[0] = $aInfo[0] ; Row $aHit[1] = $aInfo[1] ; Col Else $aHit[0] = -1 ; Row $aHit[1] = -1 ; Col EndIf _GUICtrlListView_RedrawItems( $hLV, $iItem, $iItem ) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem Local $dwItemSpec = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index Local $iSubItem = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem" ) ; Subitem index Local $uItemState = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" ) ; Item state If $dwItemSpec = $aHit[0] Then ; Marked row Switch $iSubItem Case $aHit[1] ; Marked column DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR Case Else ; Other columns DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) ; Forecolor black DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) ; Backcolor white EndSwitch Else ; Other rows DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
OldNoob Posted August 19, 2015 Share Posted August 19, 2015 Hopefully this thread is not to old to post a reply to...I noticed odd behavior when I modify the line of code that creates the list viewLocal $idLV1 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 125, 145, 250, 250, Default, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES ))It seems when anything is added into the extended style field I am only able to select an item in the listview from the first column. I would like to understand why that is?Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 19, 2015 Moderators Share Posted August 19, 2015 OldNoob,You should always set extended styles for ListViews using the _GUICtrlListView_SetExtendedListViewStyle function as some of the ListView extended styles share numerical values with GUI extended styles (a MicroSoft problem and nothing to do with AutoIt). As a result, if there is a conflict Windows acts on the $WS_EX_* style and not the $LVS_EX_* one. - which is what I imagine is happening to you.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted August 19, 2015 Share Posted August 19, 2015 It's also very likely that happens because the default extended style is $LVS_EX_FULLROWSELECT, and when you set new values to the extended parameters you removed the one that was the default. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
OldNoob Posted August 21, 2015 Share Posted August 21, 2015 Melba23 & KingBob,Thank you both for the explanation. I re-tried by adding $LVS_EX_FULLROWSELECT to the BitOR statement and it worked perfectly. Although functionally not required I find the listview more visually appealing with the gridlines and clientedge. Local $idLV1 = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 125, 145, 250, 250, Default, BitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES )) 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