Jump to content

Show Only selected cell or no cell in listview


Go to solution Solved by PhoenixXL,

Recommended Posts

Hello all, I am using a listview to hold data, and as it happens, each cell in the list view is an independent selection, however, when I use gridlines, II can only select the first item in the list, and without gridlines, the whole row is selected.

Is there any way to allow either just the element clicked to be highlighted, or to prevent the control from highlighting the row all together?

Link to comment
Share on other sites

  • Moderators

nullshritt,

Alas I believe not. The $LVS_EX_FULLROWSELECT extended style determines whether the whole row is selected or not, but I have yet to find a way to highlight just a single subitem. I have seen some scripts involving an overlaid label, but it was difficult to keep the label in the correct place as the ListView scrolled. If I ever find a way I will be certain to post - please do the same. :(

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

Check Out Example

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $iCheckBox[2], $hListView

_Main()

Func _Main()
    Local $hImage, $hListView

    GUICreate("ListView Get Extended List View Style", 400, 300)

    $iCheckBox[0] = GUICtrlCreateCheckbox("LVS_EX_GRIDLINES", 12, 280, 150, 20)
    $iCheckBox[1] = GUICtrlCreateCheckbox("LVS_EX_FULLROWSELECT", 172, 280, 170, 20)

    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, 0)
    GUISetState()


    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    _GUICtrlListView_InsertItem($hListView, "Row 1: Col 1", -1, 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_InsertItem($hListView, "Row 2: Col 1", -1, 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_InsertItem($hListView, "Row 3: Col 1", -1, 2)

    ; Loop until user exits
    Do

        $nMsg = GUIGetMsg()

        Switch $nMsg

            Case $iCheckBox[0], $iCheckBox[1]

                $iStyle = Eval(GUICtrlRead($nMsg, 1))
                $iRemove = Int(GUICtrlRead($nMsg)) - 1

                $iCurStyle = _GUICtrlListView_GetExtendedListViewStyle($hListView)

                If $iRemove Then
                    $iNewStyle = BitXOR($iCurStyle, $iStyle)
                Else
                    $iNewStyle = BitOR($iCurStyle, $iStyle)
                EndIf

                _GUICtrlListView_SetExtendedListViewStyle($hListView, $iNewStyle)

        EndSwitch

    Until $nMsg = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Check Out Example

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $iCheckBox[2], $hListView

_Main()

Func _Main()
    Local $hImage, $hListView

    GUICreate("ListView Get Extended List View Style", 400, 300)

    $iCheckBox[0] = GUICtrlCreateCheckbox("LVS_EX_GRIDLINES", 12, 280, 150, 20)
    $iCheckBox[1] = GUICtrlCreateCheckbox("LVS_EX_FULLROWSELECT", 172, 280, 170, 20)

    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, 0)
    GUISetState()


    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    _GUICtrlListView_InsertItem($hListView, "Row 1: Col 1", -1, 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_InsertItem($hListView, "Row 2: Col 1", -1, 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_InsertItem($hListView, "Row 3: Col 1", -1, 2)

    ; Loop until user exits
    Do

        $nMsg = GUIGetMsg()

        Switch $nMsg

            Case $iCheckBox[0], $iCheckBox[1]

                $iStyle = Eval(GUICtrlRead($nMsg, 1))
                $iRemove = Int(GUICtrlRead($nMsg)) - 1

                $iCurStyle = _GUICtrlListView_GetExtendedListViewStyle($hListView)

                If $iRemove Then
                    $iNewStyle = BitXOR($iCurStyle, $iStyle)
                Else
                    $iNewStyle = BitOR($iCurStyle, $iStyle)
                EndIf

                _GUICtrlListView_SetExtendedListViewStyle($hListView, $iNewStyle)

        EndSwitch

    Until $nMsg = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

I am having a problem.... whenever I disable full_row_select, I cannot get the value of any item except the first in the row, with WN_NOTIFY

 

Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
$texts = _GUICtrlListView_GetItemText($hWndFrom, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
_DebugPrint($texts)

Is there an alternative way to capture the clicked element, or to simply hide the select area, rather than disable clicking on the rest of the row?

Link to comment
Share on other sites

You mean this ?

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $GUI = GUICreate("", 300, 450)
Global $listView = GUICtrlCreateListView("A|B|C|D|E|F|G", 25, 25, 250, 400, -1, $LVS_EX_GRIDLINES+$LVS_EX_FULLROWSELECT)
For $i = 0 To 20
    GUICtrlCreateListViewItem("A" & $i & "|B" & $i & "|C" & $i & "|D" & $i & "|E" & $i & "|F" & $i & "|G" & $i, $listView)
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") 

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
     Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
     $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
     $iCode = DllStructGetData($tNMHDR, "Code")
     $hListView = GuiCtrlGetHandle($listView)

    Switch $hWndFrom
         Case $hListView
             Switch $iCode
                 Case $NM_CLICK  ; DBLCLK
                     Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                     $click_item = DllStructGetData($tInfo, "Index")
                     $click_subItem = DllStructGetData($tInfo, "SubItem") 
                    If $click_item<>-1 Then Msgbox(0,"", _GUICtrlListView_GetItemText($hListView, $click_item, $click_subItem))
               Case $NM_CUSTOMDRAW
                     Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                     Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                     Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                     Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                     If $iDrawStage = $CDDS_ITEMPREPAINT Then 
                          ControlListView($gui, "", $listview, "DeSelect", $iItem)
                         _GUICtrlListView_SetItemFocused($hListView, $iItem, false)
                    EndIf
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY
Edited by mikell
Link to comment
Share on other sites

 

You mean this ?

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $GUI = GUICreate("", 300, 450)
Global $listView = GUICtrlCreateListView("A|B|C|D|E|F|G", 25, 25, 250, 400, -1, $LVS_EX_GRIDLINES+$LVS_EX_FULLROWSELECT)
For $i = 0 To 20
    GUICtrlCreateListViewItem("A" & $i & "|B" & $i & "|C" & $i & "|D" & $i & "|E" & $i & "|F" & $i & "|G" & $i, $listView)
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") 

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
     Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
     $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
     $iCode = DllStructGetData($tNMHDR, "Code")
     $hListView = GuiCtrlGetHandle($listView)

    Switch $hWndFrom
         Case $hListView
             Switch $iCode
                 Case $NM_CLICK  ; DBLCLK
                     Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                     $click_item = DllStructGetData($tInfo, "Index")
                     $click_subItem = DllStructGetData($tInfo, "SubItem") 
                    If $click_item<>-1 Then Msgbox(0,"", _GUICtrlListView_GetItemText($hListView, $click_item, $click_subItem))
               Case $NM_CUSTOMDRAW
                     Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                     Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                     Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                     Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                     If $iDrawStage = $CDDS_ITEMPREPAINT Then 
                          ControlListView($gui, "", $listview, "DeSelect", $iItem)
                         _GUICtrlListView_SetItemFocused($hListView, $iItem, false)
                    EndIf
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY

No, that's the same as the code I have, please try running an example where fullrowselect is not an extended style

with:

_GUICtrlListView_SetExtendedListViewStyle($hListView, 0)

You will see that only the first column of each row can be selected, and any other clicked objects will return null text...

I am trying to allow anywhere on the row to be clicked, without highlighting the whole row....

Edited by nullschritt
Link to comment
Share on other sites

  • Solution

Have a look

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

GUICreate("", 300, 450)
Local $listView = GUICtrlCreateListView("A|B|C|D|E|F|G", 25, 25, 250, 400, -1, $LVS_EX_GRIDLINES)

For $i = 0 To 20
    GUICtrlCreateListViewItem("A" & $i & "|B" & $i & "|C" & $i & "|D" & $i & "|E" & $i & "|F" & $i & "|G" & $i, $listView)
Next
$listView = GUICtrlGetHandle($listView) ;the example didn't work when used with ControlID.

;lets do it by handling the primary down event.
GUISetState()

Local $nMsg, $aInfo

Do

    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN

            $s_Item = GetItemClicked($listView)
            If @error = 0 Then ConsoleWrite($s_Item & ": was clicked" & @CRLF)

    EndSwitch

Until $nMsg = $GUI_EVENT_CLOSE

Func GetItemClicked( $hListView )

    ;get the info
    $aInfo = _GUICtrlListView_SubItemHitTest( $hlistView )

    If $aInfo[0] = -1 Or $aInfo[1] = -1 Then Return SetError(2, 0, -1)
    If IsArray($aInfo) = 0 Then Return SetError(1, 0, -1)

    ;get the item/subitem text.
    Return _GUICtrlListView_GetItemText($hlistView, $aInfo[0], $aInfo[1])

EndFunc
 

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Have a look

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

GUICreate("", 300, 450)
Local $listView = GUICtrlCreateListView("A|B|C|D|E|F|G", 25, 25, 250, 400, -1, $LVS_EX_GRIDLINES)

For $i = 0 To 20
    GUICtrlCreateListViewItem("A" & $i & "|B" & $i & "|C" & $i & "|D" & $i & "|E" & $i & "|F" & $i & "|G" & $i, $listView)
Next
$listView = GUICtrlGetHandle($listView) ;the example didn't work when used with ControlID.

;lets do it by handling the primary down event.
GUISetState()

Local $nMsg, $aInfo

Do

    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN

            $s_Item = GetItemClicked($listView)
            If @error = 0 Then ConsoleWrite($s_Item & ": was clicked" & @CRLF)

    EndSwitch

Until $nMsg = $GUI_EVENT_CLOSE

Func GetItemClicked( $hListView )

    ;get the info
    $aInfo = _GUICtrlListView_SubItemHitTest( $hlistView )

    If $aInfo[0] = -1 Or $aInfo[1] = -1 Then Return SetError(2, 0, -1)
    If IsArray($aInfo) = 0 Then Return SetError(1, 0, -1)

    ;get the item/subitem text.
    Return _GUICtrlListView_GetItemText($hlistView, $aInfo[0], $aInfo[1])

EndFunc
 

Regards :)

ermaaahgeerd it works.

Thanks! (:

Link to comment
Share on other sites

  • 1 year later...

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