Jump to content

Listview Select Item Trouble (making A Browser)


Recommended Posts

Hi all,

I am having trouble with a browserish app I am creating.

Basically, it is a list of dirs/files. When I enter a directory and go back up, I want that directory selected.

I managed to do that with ControlListView. My problem is that when I press an up/down cursor, I only find that the caret was actually on the first item on the list, despite the directory being so nicely highlighted..

Please observe:

#include <GUIConstants.au3>
#include <Misc.au3>
#include <GuiListView.au3>
$dll = DllOpen("user32.dll")

GUICreate("test", 500, 500)

$listviewtest = GUICtrlCreateListView ("Bah1|Bah2|Bah3|Bah4", 10, 10,430,445, $LVS_LIST + $LVS_NOSORTHEADER + $LVS_SHOWSELALWAYS + $WS_BORDER + $WS_VSCROLL + $LBS_NOTIFY, $LVS_EX_FULLROWSELECT + $LVS_EX_HEADERDRAGDROP + $LVS_EX_GRIDLINES);+ $LVS_EX_CHECKBOXES)
_FirstLevel()

GUISetState(@SW_SHOW)

While 1
 sleep(50)

;If enter pressed..
 If _IsPressed("0D", $dll) Then
    If WinActive ( "test" ) = 1 Then
        $item = GUICtrlRead(GUICtrlRead($listviewtest))
        $item = StringSplit($item, "|", 0)
    ;detecting if selected item is a directory, file or an 'up-level-you-go-tridot-thingie'
     Select
        case $item[4] = "directory"
        $dir = _GUICtrlListViewGetCurSel($listviewtest)
        _SecondLevel()
        
        case else
         If $item[4] = "..." Then
            $item = "..."
           Else
              $item = "file"
         EndIf  
      EndSelect             
        
;now, depending on the itemtype selected, enter deeper into the dungon..
      Select
            case $item = "..."
            _FirstLevel()
            ControlListView ( "test", "", $listviewtest, "Select", $dir)
            case else
    EndSelect
    EndIf
 EndIf

    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _FirstLevel()
    _GUICtrlListViewDeleteAllItems($listviewtest)
    GUICtrlCreateListViewItem ("a1|a2|a3|file", $listviewtest )
    GUICtrlCreateListViewItem ("b1|b2|b3|file", $listviewtest )
    GUICtrlCreateListViewItem ("c1|c2|c3|file", $listviewtest )
    GUICtrlCreateListViewItem ("x1|x2|x3|directory", $listviewtest )
    GUICtrlCreateListViewItem ("d1|d2|d3|file", $listviewtest )
EndFunc

Func _SecondLevel()
    _GUICtrlListViewDeleteAllItems($listviewtest)
    GUICtrlCreateListViewItem ("up|up|up|...", $listviewtest )
    GUICtrlCreateListViewItem ("A1|A2|A3|file", $listviewtest )
    GUICtrlCreateListViewItem ("B1|B2|B3|file", $listviewtest )
    GUICtrlCreateListViewItem ("C1|C2|C3|file", $listviewtest )
    GUICtrlCreateListViewItem ("D1|D2|D3|file", $listviewtest )
    GUICtrlCreateListViewItem ("E1|E2|E3|file", $listviewtest )
EndFunc
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Misc.au3>
#include <GuiListView.au3>
$dll = DllOpen("user32.dll")

GUICreate("test", 500, 500)

$listviewtest = GUICtrlCreateListView("Bah1|Bah2|Bah3|Bah4", 10, 10, 430, 445, $LVS_LIST + $LVS_NOSORTHEADER + $LVS_SHOWSELALWAYS + $WS_BORDER + $WS_VSCROLL + $LBS_NOTIFY, $LVS_EX_FULLROWSELECT + $LVS_EX_HEADERDRAGDROP + $LVS_EX_GRIDLINES);+ $LVS_EX_CHECKBOXES)
_FirstLevel()

GUISetState(@SW_SHOW)

While 1
    Sleep(50)
    
;If enter pressed..
    If _IsPressed("0D", $dll) Then
        If WinActive("test") = 1 Then
            $item = GUICtrlRead(GUICtrlRead($listviewtest))
            $item = StringSplit($item, "|", 0)
        ;detecting if selected item is a directory, file or an 'up-level-you-go-tridot-thingie'
            Select
                Case $item[4] = "directory"
                    $dir = _GUICtrlListViewGetCurSel($listviewtest)
                    _SecondLevel()
                    
                Case Else
                    If $item[4] = "..." Then
                        $item = "..."
                        _FirstLevel()
                        _GUICtrlListViewSetItemSelState ($listviewtest, $dir)
                        _GUICtrlListViewSetHotItem($listviewtest, $dir)

                    Else
                        $item = "file"
                    EndIf
            EndSelect
            
        EndIf
    EndIf
    
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _FirstLevel()
    _GUICtrlListViewDeleteAllItems($listviewtest)
    GUICtrlCreateListViewItem("a1|a2|a3|file", $listviewtest)
    GUICtrlCreateListViewItem("b1|b2|b3|file", $listviewtest)
    GUICtrlCreateListViewItem("c1|c2|c3|file", $listviewtest)
    GUICtrlCreateListViewItem("x1|x2|x3|directory", $listviewtest)
    GUICtrlCreateListViewItem("d1|d2|d3|file", $listviewtest)
EndFunc  ;==>_FirstLevel

Func _SecondLevel()
    _GUICtrlListViewDeleteAllItems($listviewtest)
    GUICtrlCreateListViewItem("up|up|up|...", $listviewtest)
    GUICtrlCreateListViewItem("A1|A2|A3|file", $listviewtest)
    GUICtrlCreateListViewItem("B1|B2|B3|file", $listviewtest)
    GUICtrlCreateListViewItem("C1|C2|C3|file", $listviewtest)
    GUICtrlCreateListViewItem("D1|D2|D3|file", $listviewtest)
    GUICtrlCreateListViewItem("E1|E2|E3|file", $listviewtest)
EndFunc  ;==>_SecondLevel

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

_GUICtrlListViewSetItemSelState ($listviewtest, $dir)
                        _GUICtrlListViewSetHotItem($listviewtest, $dir)
Thank you for the reply, I am afraid it isn't quite it, though.

After I go into the directory, and back again I have that directory nicely highlighted. The problem is, when I want to navigate further down and press DOWN, I still get 'a1|a2|a3|file' selected instead of 'd1|d2|d3|d4|file'.

Now, I am not exactly sure what this SetHotItem business is all about.. The documentation's example I run didn't change the selection of the SetHotItem'ed item either.. I could GetHotItem the index, but there was no visible change to the item itself..

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