Sign in to follow this  
Followers 0

Multiple ListViews

5 posts in this topic

Posted

Hi Guys

I've written an app that has two listviews on one gui, they show the file contents of two different folders.

The two listviews are called $paidview and $unpaid view

Inside the gui msg loop, I use this to open the document that you have selected

$x=number(_GUICtrlListView_GetSelectedIndices ($paidView))
        run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($paidview, $x,4)),@ScriptDir,@SW_HIDE)

Now this is all good, but here is the problem.

I am only working with the $paidview guilist. I have no idea how I can determine first which guilist you have selected, because actually both guilists have selected indices.

Ideally I need something like this

$l=_Getlastclickedguilist
        $x=number(_GUICtrlListView_GetSelectedIndices ($l))
        run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($l, $x,4)),@ScriptDir,@SW_HIDE)

But obviously thats just a dream! Maybe someone can help make my dream come true today?!

N

Share this post


Link to post
Share on other sites



Posted

Hi Guys

I've written an app that has two listviews on one gui, they show the file contents of two different folders.

The two listviews are called $paidview and $unpaid view

Inside the gui msg loop, I use this to open the document that you have selected

$x=number(_GUICtrlListView_GetSelectedIndices ($paidView))
        run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($paidview, $x,4)),@ScriptDir,@SW_HIDE)

Now this is all good, but here is the problem.

I am only working with the $paidview guilist. I have no idea how I can determine first which guilist you have selected, because actually both guilists have selected indices.

Ideally I need something like this

$l=_Getlastclickedguilist
        $x=number(_GUICtrlListView_GetSelectedIndices ($l))
        run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($l, $x,4)),@ScriptDir,@SW_HIDE)

But obviously thats just a dream! Maybe someone can help make my dream come true today?!

N

You could use

$CursorInfo = GuiGetCursorInfo

inside a while loop maybe. From this you can see if the mouse button is down and the control the mouse is over.

If $CursorInfo[2] then;if primary down
  if $CursorInfo[4] = $paidview or $cursorInfo[4] = $unpaid then $LastselectedLV = $CursorInfo[4];set to component mouse is over
endif

Share this post


Link to post
Share on other sites

Posted

Firstly, thank you - thats actually an answer I can understand for once :)

It works well but with 1 flaw; timing.

Seems like 'If $CursorInfo[2] then' is a bit hit and miss, depends if you click right at the point it runs in the loop below. Clicking several times on the item you want ensures that you get the right result but is obviously not great..

Not sure where to go now with this one...

GUISetState(@SW_SHOW)

do
    $msg = GUIGetMsg()
    
    $CursorInfo = GuiGetCursorInfo ($invoicegui)
    If $CursorInfo[2] then;if primary down
        if $CursorInfo[4] = $paidview or $cursorInfo[4] = $unpaidview then $ncursorresult = $CursorInfo[4];set to component mouse is over
    EndIf
    If $msg = $opendoc And $ncursorresult = $unpaidview Then
        $x=number(_GUICtrlListView_GetSelectedIndices ($unpaidview))
    ;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($unpaidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'', _GUICtrlListView_GetItemText ($unpaidview, $x,4))
    EndIf
    If $msg = $opendoc And $ncursorresult = $paidview Then
        $x=number(_GUICtrlListView_GetSelectedIndices ($PaidView))
    ;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($Paidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'', _GUICtrlListView_GetItemText ($paidview, $x,4))
    EndIf

until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites

Posted

Firstly, thank you - thats actually an answer I can understand for once :)

It works well but with 1 flaw; timing.

Seems like 'If $CursorInfo[2] then' is a bit hit and miss, depends if you click right at the point it runs in the loop below. Clicking several times on the item you want ensures that you get the right result but is obviously not great..

Not sure where to go now with this one...

GUISetState(@SW_SHOW)

do
    $msg = GUIGetMsg()
    
    $CursorInfo = GuiGetCursorInfo ($invoicegui)
    If $CursorInfo[2] then;if primary down
        if $CursorInfo[4] = $paidview or $cursorInfo[4] = $unpaidview then $ncursorresult = $CursorInfo[4];set to component mouse is over
    EndIf
    If $msg = $opendoc And $ncursorresult = $unpaidview Then
        $x=number(_GUICtrlListView_GetSelectedIndices ($unpaidview))
;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($unpaidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'', _GUICtrlListView_GetItemText ($unpaidview, $x,4))
    EndIf
    If $msg = $opendoc And $ncursorresult = $paidview Then
        $x=number(_GUICtrlListView_GetSelectedIndices ($PaidView))
;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($Paidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'', _GUICtrlListView_GetItemText ($paidview, $x,4))
    EndIf

until $msg = $GUI_EVENT_CLOSE

Try this

#include <guiconstants.au3>
#include <guilistview.au3>
#include <constants.au3>
Global $ncursorresult
$invoicegui = guicreate("inv")

$unpaidview = guictrlcreatelistview("unpaid",10,10,100,200)
$item1=GUICtrlCreateListViewItem("item2|col22|col23",$unpaidview)
$item2=GUICtrlCreateListViewItem("item1|col12|col13",$unpaidview)
$item3=GUICtrlCreateListViewItem("item3|col32|col33",$unpaidview)

$paidview = guictrlcreatelistview('paid',130,10,100,200)
$item1=GUICtrlCreateListViewItem("item2|col22|col23",$paidview)
$item2=GUICtrlCreateListViewItem("item1|col12|col13",$paidview)
$item3=GUICtrlCreateListViewItem("item3|col32|col33",$paidview)
$opendoc = GUICtrlCreateButton("opendoc",20,240,100,21)
GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
do
    $msg = GUIGetMsg()
  
    
    If $msg = $opendoc And $ncursorresult = $unpaidview Then
        consolewrite("1) msg = " & $msg & '$ncursorresult = ' & $ncursorresult & @LF)
        $x=number(_GUICtrlListView_GetSelectedIndices ($unpaidview))
    
    
   ;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($unpaidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'unpaid', _GUICtrlListView_GetItemText ($unpaidview, $x,0))
    EndIf
    If $msg = $opendoc And $ncursorresult = $paidview Then
        consolewrite("2) msg = " & $msg & '$ncursorresult = ' & $ncursorresult & @LF)
        $x=number(_GUICtrlListView_GetSelectedIndices ($PaidView))
   ;run(@comspec & ' /c start /max ' & FileGetShortName( _GUICtrlListView_GetItemText ($Paidview, $x,4)),@ScriptDir,@SW_HIDE)
        msgbox(262144,'paid', _GUICtrlListView_GetItemText ($paidview, $x,0))
    EndIf

until $msg = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hpaid, $hunpaid
    $hpaid = GUICtrlGetHandle($paidview)
    $hunpaid = GUICtrlGetHandle($unpaidview)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
     if $hWnd = $invoicegui and $iCode =  $NM_CLICK  Then
                    if $hWndFrom = $hunpaid then $ncursorresult = $unpaidview
                    if $hWndFrom = $hpaid then $ncursorresult = $paidview
                    Return 0 
                
            EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

Share this post


Link to post
Share on other sites

Posted

WOW thanks! You saved me a lot of head scratching.

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