Sign in to follow this  
Followers 0
JRowe

Listview subitems not selectable, etc.

4 posts in this topic

Ok, I've wrestled with the editable listview thats on the forums, and frankly, it makes my head hurt trying to go through it. No offense to eltorro, but I think the grid control effect can be achieved in a much easier fashion.

I was wondering if someone could post or point me to the snippets needed.

I need to know how to change the selected/highlight status. Everything else seems to be easily doable or built in.

Double clicks on the control can be registered and editboxes placed in the appropriate areas to achieve editing, since it's so easy to get/set item and subitem text. No problems there.

Change the text/value of a specific item or sub item:

_GUICtrlListView_SetItem($hWnd, $sText,[ $iIndex = 0, $iSubItem = 0])

Determine what item or sub item has been clicked on:

_GuiCtrlListView_SubItemHitTest ($hWnd)

Retrieve what's in a specific item/subitem:

_GUICtrlListView_GetItemText($hWnd, $iIndex[, $iSubItem = 0])

So, to achieve the effect I'm looking for, I would:

Check for the cell selected

Change the cell to highlighted

If a double click was registered then

create a new edit box sized accordingly directly over the selected cell

on enter or other input, set the data/text of the cell to the edited version.

Seems very simple to me, and adding UDLR navigation would be cake.

Just need to figure out how to highlight a subitem.

Share this post


Link to post
Share on other sites



Try this:

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

$hGUI = GUICreate("Test GUI", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    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")
    
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    If DllStructGetData($tInfo, "SubItem") <> 0 Then _GetSubItem()
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _GetSubItem()
    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If $aHit[1] = -1 Then Return False
    
    ConsoleWrite($aHit[0] + 1 & " SubItem selected" & @LF)
EndFunc

Share this post


Link to post
Share on other sites

Thank you, but I had already figured that out. I'm trying to figure out how to highlight the selected subitem. I should have been more clear in the original post.

It's just the highlighting that's giving me grief.

Share this post


Link to post
Share on other sites

If you want selection highlight on a subitem instead of a row, you have to draw it yourself. Search forum for listview NM_CUSTOMDRAW example.


"be smart, drink your wine"

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