Sign in to follow this  
Followers 0
nhardel

Listview with clickable cells?

7 posts in this topic

Okay, who is ready to point me to the quickest answer ever on this forum?  I am attempting to make a listview type control and cant get my head around how to pull this off.

Requirements

DYNAMIC number of rows and columns

Autoscroll capabilities for a set ctrl size

Ability to click individual cells

Issues with listviews

I can select an item but that really just selects the whole row - perhaps I am missing a style or exstyle setting?

meets all other requirements

Issues with table.au3  even modified to use input boxes

Don't know how I would stick entire table into some type of ctrl box that would do the autoscroll capabilities when the table starts to get large

Groupbox?

Issues with Embeded excel

No way to know for sure that computer that is being used will have excel

Don't want to go down the road of making sure installed if I don't have to.

Another possible answer is Gridviews

but there isnt much info on these in the forum other than how to interact with one already in another application.  Not sure how I might go about creating one for myself in autoit

So there we go, I have scoured the forums and I can post some code if that helps.  Not sure how it will as the code I have works as expected from an Autoit standpoint, just not what I need.    Let the 'Ah Ha' moments begin! :thumbsup:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

nhardel,

I have been looking for a way to hightlight individual cells in a ListView for a long time and never found anything really satisfactory. This is the best I have ever managed myself based on my GUIListViewEx UDF:

 

Let me know what you think. :)

M23

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Wow, my skills must be improving.  I have stumped one of the AutoIT sorcerers. :sorcerer:   

Melba,

Looking thru the sample script, I see your point.  It works but man, ouch.  I don't need to really edit the cell, just recognize what cell it is and maybe change the background color so the user knows that they selected that cell.  I think I can adapt what you have to pull this off, still looking thru it and at work so tons of interuptions.  It really seems like such a simple request for individual selectable cells.  :think:  Thanks for the input.

To all others

Keep the ideas coming.  As you can see there is a demand for a good way to do this. 

Share this post


Link to post
Share on other sites

nhardel,

 

It works but man, ouch

I could not have put it better myself! :D

But seriously, if all you are looking for is to highlight a single cell then it should be possible to reduce the code significantly. We are forecast a wet weekend here - so if you think there is some merit in the line I have taken I could see what I could develop. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

May be a custom drawn listview:

 

#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", 300, 222 )

  Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 300-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
  Local Static $bItemChanged
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom

    Case $hLV

      Switch $iCode

        Case $LVN_ITEMCHANGED
          $bItemChanged = True
          Local $aInfo = GUIGetCursorInfo( $hGui )
          If $aInfo[2] Then
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
            If $aInfo[0] > -1 And $aInfo[1] > -1 Then
              If $aHit[0] > -1 Then _
                _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              $aHit[0] = $aInfo[0] ; Row
              $aHit[1] = $aInfo[1] ; Col
              _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            EndIf
          Else
            Local $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
            _GUICtrlListView_SetItemSelected( $hLV, DllStructGetData( $tNMLISTVIEW, "Item" ), False )
          EndIf

        Case $NM_CLICK
          If Not $bItemChanged Then
            Local $aInfo = GUIGetCursorInfo( $hGui )
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
            If $aInfo[0] > -1 And $aInfo[1] > -1 Then
              If $aHit[0] > -1 Then _
                _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              $aHit[0] = $aInfo[0] ; Row
              $aHit[1] = $aInfo[1] ; Col
              _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            EndIf
          EndIf
          $bItemChanged = False

        Case $NM_RCLICK
          Local $aInfo = GUIGetCursorInfo( $hGui )
          $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
          If $aInfo[0] = $aHit[0] And $aInfo[1] = $aHit[1] Then
            _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
            _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            $aHit[0] = -1 ; Row
            $aHit[1] = -1 ; Col
          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",   0x000000 )      ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )      ; Backcolor cyan, BGR
                  Case Else ; Other columns
                    If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )    ; Forecolor white
                      DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )    ; Backcolor dark blue, BGR
                    Else
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )    ; Forecolor black
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )    ; Backcolor white
                    EndIf
                EndSwitch
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
                EndIf
              EndIf
              Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

          EndSwitch

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Edit: Added code for NM_CLICK-event.

Edit 2: Right click to unmark.

Edit 3: Don't use this code. Use the code in post 6 or 7.

Edited by LarsJ
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Click to mark. Click once more to unmark.

 

#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",   0x000000 )      ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )      ; Backcolor cyan, BGR
                  Case Else ; Other columns
                    If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )    ; Forecolor white
                      DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )    ; Backcolor dark blue, BGR
                    Else
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )    ; Forecolor black
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )    ; Backcolor white
                    EndIf
                EndSwitch
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
                EndIf
              EndIf
              Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

          EndSwitch

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Edit: Forgot to take into account that the upper left corner of the listview is ( 2, 2 ) and not ( 0, 0 ). Cleaned up the code.

Edited by LarsJ

Share this post


Link to post
Share on other sites

Multiple cells.

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
;#include <Array.au3>

Opt( "MustDeclareVars", 1 )

Global $hGui, $hLV

; $aMarkedCells is used to store columns with marked cells. Line (index) in $aMarkedCells is stored in ItemParam. When all
; marks in a row are cleared the line in question in $aMarkedCells can be reused. Line (index) is stored in $aNotUsedLines.
Global $iMarkedCells = 0, $aMarkedCells[10][4] ; Col 3 = number of marked cells per row
Global $iNotUsedLines = 0, $aNotUsedLines[10]

MainFunc()

Func MainFunc()

  $hGui = GUICreate( "Mark Cells in Listview", 250, 222, 300, 300 )

  Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 250-4, 222-4 ), $idx
  $hLV = ControlGetHandle( $hGui, "", $idLV )
  ; ItemParam will be used to keep track of marked cells
  ; Create rows with _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem
  ; (For rows created with GUICtrlCreateListViewItem ControlID is stored in ItemParam)
  For $i = 0 To 49
    $idx = _GUICtrlListView_AddItem( $hLV, "Cell " & $i & ".0" )
    _GUICtrlListView_AddSubItem( $hLV, $idx, "Cell " & $i & ".1", 1 )
    _GUICtrlListView_AddSubItem( $hLV, $idx, "Cell " & $i & ".2", 2 )
    ;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_SECONDARYDOWN
      ;  _ArrayDisplay( $aMarkedCells, "$aMarkedCells" )
      ;  _ArrayDisplay( $aNotUsedLines, "$aNotUsedLines" )
      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, $iParam, $aInfo
          $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
          $iItem = DllStructGetData( $tNMLISTVIEW, "Item" )
          $iParam = DllStructGetData( $tNMLISTVIEW, "Param" )
          _GUICtrlListView_SetItemSelected( $hLV, $iItem, False )

          $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 Not $iParam Then
                ; First mark in row
                Local $idxMarkedCells
                If $iNotUsedLines Then ; Unused lines in $aMarkedCells?
                  $idxMarkedCells = $aNotUsedLines[$iNotUsedLines-1]
                  $iNotUsedLines -= 1
                Else ; Allocate a new line in $aMarkedCells?
                  $idxMarkedCells = $iMarkedCells
                  $iMarkedCells += 1
                  If Mod( $iMarkedCells, 10 ) = 0 Then _
                    ReDim $aMarkedCells[$iMarkedCells+10][4]
                EndIf
                $aMarkedCells[$idxMarkedCells][3] = 1
                $aMarkedCells[$idxMarkedCells][$aInfo[1]] = 1
                _GUICtrlListView_SetItemParam( $hLV, $iItem, $idxMarkedCells + 1 )
              Else
                $iParam -= 1
                If Not $aMarkedCells[$iParam][$aInfo[1]] Then
                  ; Add mark in row
                  $aMarkedCells[$iParam][$aInfo[1]] = 1
                  $aMarkedCells[$iParam][3] += 1
                Else
                  ; Del mark in row
                  $aMarkedCells[$iParam][$aInfo[1]] = 0
                  $aMarkedCells[$iParam][3] -= 1
                  If Not $aMarkedCells[$iParam][3] Then
                    _GUICtrlListView_SetItemParam( $hLV, $iItem, 0 )
                    ; When all marks in a row are cleared store the line (index) from $aMarkedCells in
                    ; $aNotUsedLines. This line can be reused to store marks in another row in the LV.
                    $aNotUsedLines[$iNotUsedLines] = $iParam
                    $iNotUsedLines += 1
                    If Mod( $iNotUsedLines, 10 ) = 0 Then _
                      ReDim $aNotUsedLines[$iNotUsedLines+10]
                  EndIf
                EndIf
              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 $lItemlParam = DllStructGetData( $tNMLVCUSTOMDRAW, "lItemlParam" ) ; Item param
              Local $iSubItem    = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem"   )  ; Subitem index
              Local $uItemState  = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" )  ; Item state
              If $lItemlParam Then ; Marked row
                If $aMarkedCells[$lItemlParam-1][$iSubItem] Then ; Marked column
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )          ; Forecolor black
                  If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0x00FFFF )        ; Backcolor yellow, BGR
                  Else
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )        ; Backcolor cyan, BGR
                  EndIf
                Else ; Other columns
                  If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )        ; Forecolor white
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )        ; Backcolor dark blue, BGR
                  Else
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )        ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )        ; Backcolor white
                  EndIf
                EndIf
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )
                EndIf
              EndIf
              Return $CDRF_NEWFONT                          ; $CDRF_NEWFONT must be returned after changing font or colors

          EndSwitch

      EndSwitch

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • islandspapand
      By islandspapand
      Hi all
      i am currently trying to click on an element in a HTML Table, but just can get it to work.
      i am able to click the top of the table so it changes to sort  but just can't click on the element in the table.
      an i need to click on element to continue in the site.
      i have attached the code so far and pictures of the table  element want to click plus the source of the table.
      i am able to get data in the table with $oTable = _IETableGetCollection($oIE, 2) but not able to click on them.
       
      Help is very much appreciated
       
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <IE.au3> #include "DOM.au3" #include <Array.au3> #include <MsgBoxConstants.au3> Global $oIE = _IECreate("*") _IELoadWait($oIE) Sleep(2000) _PageLogin($oIE) _PageLoadWait() _PageNewReq($oIE) _PageLoadWait() _InputModelInf($oIE) _PageLoadWait() Sleep(1000) $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr/td[.='Name Of user']", 2000) ;~ $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr", 2000) ;~ _ArrayDisplay($aTableLink,"$aTableLink") If IsArray($aTableLink) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) For $i = 0 To UBound($aTableLink)-1 ConsoleWrite(" OuterHTML : " & $aTableLink[$i].outerHTML & @CRLF) ConsoleWrite(" Parentnode : " & $aTableLink[$i].parentnode & @CRLF) ConsoleWrite(" Parentnode.click : " & $aTableLink[$i].parentnode.fireEvent("onclick","click") & @CRLF) $objClick = $aTableLink[$i].parentnode ;~ _IEAction($aTableLink[$i] , "focus") _IEAction($objClick , "focus") ;~ If _IEAction($aTableLink[$i], "click") Then If _IEAction($objClick, "click") Then ConsoleWrite("Able to _IEAction($aForumLink[0], 'click')" & @CRLF) _IELoadWait($oIE) Else ConsoleWrite("UNable to _IEAction($aForumLink[0], 'click')" & @CRLF) Exit 3 EndIf Next Else ConsoleWrite("Unable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) Exit 2 EndIf _PageLoadWait() Func _InputModelInf($oTmpIE) ; Add Var for Model & Serial in Func $oModelInput = _IEGetObjById($oTmpIE,"model") _IEAction($oModelInput,"focus") _IEDocInsertText($oModelInput, "*") $oSerialInput = _IEGetObjById($oTmpIE,"serial") _IEAction($oModelInput,"focus") _IEDocInsertText($oSerialInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary ng-scope") For $link In $links If $link.innertext = "Søg" Or $link.innertext = "Search" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageNewReq($oTmpIE) $links = $oTmpIE.document.getElementsByClassName("ng-scope k-link") For $link In $links If $link.innertext = "Send ny fejlmelding" Or $link.innertext = "Submit a New Service Request" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLogin($oTmpIE) $oUserInput = _IEGetObjById($oTmpIE,"loginid") _IEDocInsertText($oUserInput, "*") $oPasswordInput = _IEGetObjById($oTmpIE,"password") _IEDocInsertText($oPasswordInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary login ng-scope") For $link In $links If $link.innertext = "Sign in" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLoadWait() Local $PageLoadWait = False ;~ nav navbar-nav navbar-right ng-hide ;~ nav navbar-nav navbar-right $tags = $oIE.document.GetElementsByTagName("ul") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage loading :) ' & @CRLF) ;### Debug Console $PageLoadWait = True ExitLoop EndIf Next Do sleep(250) For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right ng-hide" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage load finished :)'& @CRLF) ;### Debug Console $PageLoadWait = False ExitLoop EndIf Next Until $PageLoadWait = False EndFunc  
      Thanks in advance
       
       


    • mLipok
      By mLipok
      I was not lucky to find the right function so I created it by my self:
      _GUICtrlListView_GetColumnID_ByName()
      Example:
       
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("ListView Get Column ID", 400, 300) Local $idListview = GUICtrlCreateListView("Alfa|Beta|Gama", 2, 2, 394, 268) GUISetState(@SW_SHOW) _GUICtrlListView_SetColumnOrder($idListview, "2|0|1") MsgBox($MB_SYSTEMMODAL, "Information", "Column ID: " & _GUICtrlListView_GetColumnID_ByName($idListview, 'Gama')) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func _GUICtrlListView_GetColumnID_ByName($hListView, $sColumnToFind) Local $iColumn_Count = _GUICtrlListView_GetColumnCount($hListView) Local $aColumns For $iColumn_idx = 0 To $iColumn_Count - 1 $aColumns = _GUICtrlListView_GetColumn($hListView, $iColumn_idx) If $aColumns[5] = $sColumnToFind Then Return $iColumn_idx EndIf Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetColumnID_ByName  
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • 0Ethan0
      By 0Ethan0
      Ahoy Autoit Community!
      After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution 
      The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
      The Setup: GUI with a ListView Control and a simple exit button.
      The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
      The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
      The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
      The Code (stripped and simplified as much as I could):
      #include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global $c=0 Global $ssGDI[3], $ssGraphic[2], $ssImage Global Const $bg_color = "000000" Global Const $ssW = 480, $ssH = 320 Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH ) $guiW = 1200 $guiH = 726 $mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP) $Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent($Button1, "_Exit") $Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent($Button1, "Test") Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth ($ListView, 0, 100) _GUICtrlListView_SetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) screenshotWidgetInit($ssW,$ssH, 690, 100) GUISetState(@SW_SHOW, $mainWindow) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For $k = 1 To UBound($aFiles) - 1 screenshotWidgetTransition($aFiles[$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000) Local $a, $d = $c, $iX, $iY $ssImage = _GDIPlus_ImageLoadFromFile($image) $iX = _GDIPlus_ImageGetWidth($ssImage) $iY = _GDIPlus_ImageGetHeight($ssImage) $FDesktop=$ssH/$ssW $Fact =1 If $iX > $ssW And $FDesktop > ($iY/$iX) Then $Fact=$ssW/$iX ElseIf $iY > $ssH Then $Fact=$ssH/$iY EndIf $H1 = Round(($Fact * $iY),0) $W1 = Round(($Fact * $iX),0) _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1) WinSetTrans($ssGDI[$d], "", 0) WinSetOnTop($ssGDI[$d], "", 1) For $a = 0 To 254 Step $speed WinSetTrans($ssGDI[$d], "", $a) Sleep($delay) Next WinSetTrans($ssGDI[$d], "", 254) WinSetOnTop($ssGDI[Not ($d)], "", 0) WinSetTrans($ssGDI[Not ($d)], "", 0) _GDIPlus_GraphicsClear($ssGraphic[Not ($d)]) $c = 1 - $d _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics Sleep($sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY) $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow) $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) ; GUISetBkColor("0x" & $bg_color, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[0]) GUISetState(@SW_SHOW, $ssGDI[1]) WinSetTrans($ssGDI[0], "", 0) WinSetTrans($ssGDI[1], "", 0) _GDIPlus_Startup() $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0]) $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1]) _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color) _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose($ssImage) _GDIPlus_GraphicsDispose($ssGraphic[0]) _GDIPlus_GraphicsDispose($ssGraphic[1]) GUIDelete($ssGDI[0]) GUIDelete($ssGDI[1]) GUIDelete($ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?
      Thank you in advance!
      P.S.
      The script is patched from different scripts of different users in the forum - thank you again users!
    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?