Jump to content

ListView - 1) no selection 2) only select subitem, not whole row


Zedna
 Share

Go to solution Solved by LarsJ,

Recommended Posts

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 ...

#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)
EndFunc

EDIT: Added: #include <WindowsConstants.au3>

Edited by Zedna
Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • Solution

Zedna, May be you can use something like this:

#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
Link to comment
Share on other sites

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 )
Link to comment
Share on other sites

  • Moderators

LarsJ,

Excellent script. I have been looking into how to do that for a long time - thanks for providing such a clean solution. :thumbsup:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by iahngy
Link to comment
Share on other sites

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  by iahngy
	
	

			
		
Link to comment
Share on other sites

Good point about the position and size. This should be better:

#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
Link to comment
Share on other sites

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 by iahngy
Link to comment
Share on other sites

Listviews on tab items:

#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
Link to comment
Share on other sites

  • 10 months later...

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 view

Local $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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...