Jump to content

[Solved] Check wich ListView in use or selected?


Go to solution Solved by Danyfirex,

Recommended Posts

I have two ListViews (with itmes), and two buttons.  

I need an idea to, if I select an item from $List1 enable  $Button1 and disable $Button2.

The other $List2 works the same vay: if I select something from $List2 then I need to disable $Button1 and enable $Button2

 

Here is myexample code, which is not working :(
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 590, 399, 589, 289)
$Button1 = GUICtrlCreateButton("Button1", 64, 272, 187, 25)
$Button2 = GUICtrlCreateButton("Button2", 320, 272, 195, 25)
$List1 = GUICtrlCreateListView("First  ", 64, 56, 185, 175)


$List2 = GUICtrlCreateListView("Second", 312, 64, 185, 175)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $idItem1 = GUICtrlCreateListViewItem("item1", $List1)
Local $idItem2 = GUICtrlCreateListViewItem("item2", $List1)
Local $idItem3 = GUICtrlCreateListViewItem("item3", $List1)
Local $idItem4 = GUICtrlCreateListViewItem("item4", $List1)
Local $idItem5 = GUICtrlCreateListViewItem("item5", $List1)

Local $idItem21 = GUICtrlCreateListViewItem("item1", $List2)
Local $idItem22 = GUICtrlCreateListViewItem("item2", $List2)
Local $idItem23 = GUICtrlCreateListViewItem("item3", $List2)
Local $idItem24 = GUICtrlCreateListViewItem("item4", $List2)
Local $idItem25 = GUICtrlCreateListViewItem("item5", $List2)


Local $iIndex = _GUICtrlListView_GetSelectedIndices($List1)
Local $iIndex2= _GUICtrlListView_GetSelectedIndices($List2)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iIndex
            ;MsgBox(0,"I","Button 1 ENable, Button2 Disable")
            GUISetState($Button1,$GUI_ENABLE)
            GUISetState($Button2,$GUI_DISABLE)

        Case $iIndex2
            ;MsgBox(0,"I","Button 2 ENable, Button1 Disable")
            GUISetState($Button2,$GUI_ENABLE)
            GUISetState($Button1,$GUI_DISABLE)

    EndSwitch



WEnd

 

Edited by DannyJ
Link to comment
Share on other sites

  • Solution

Hello, Maybe This.

 

include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 590, 399, 589, 289)
$Button1 = GUICtrlCreateButton("Button1", 64, 272, 187, 25)
$Button2 = GUICtrlCreateButton("Button2", 320, 272, 195, 25)
$List1 = GUICtrlCreateListView("First  ", 64, 56, 185, 175)


$List2 = GUICtrlCreateListView("Second", 312, 64, 185, 175)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $idItem1 = GUICtrlCreateListViewItem("item1", $List1)
Local $idItem2 = GUICtrlCreateListViewItem("item2", $List1)
Local $idItem3 = GUICtrlCreateListViewItem("item3", $List1)
Local $idItem4 = GUICtrlCreateListViewItem("item4", $List1)
Local $idItem5 = GUICtrlCreateListViewItem("item5", $List1)

Local $idItem21 = GUICtrlCreateListViewItem("item1", $List2)
Local $idItem22 = GUICtrlCreateListViewItem("item2", $List2)
Local $idItem23 = GUICtrlCreateListViewItem("item3", $List2)
Local $idItem24 = GUICtrlCreateListViewItem("item4", $List2)
Local $idItem25 = GUICtrlCreateListViewItem("item5", $List2)

GUICtrlSetState($Button1, $GUI_DISABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            Local $aInfo = GUIGetCursorInfo()
            If $aInfo[4] = $List1 Then
                ConsoleWrite("1" & @CRLF)
                GUICtrlSetState($Button1, $GUI_ENABLE)
                GUICtrlSetState($Button2, $GUI_DISABLE)
            EndIf

            If $aInfo[4] = $List2 Then
                ConsoleWrite("2" & @CRLF)
                GUICtrlSetState($Button1, $GUI_DISABLE)
                GUICtrlSetState($Button2, $GUI_ENABLE)
            EndIf
    EndSwitch
WEnd

 

Saludos

Link to comment
Share on other sites

  • DannyJ changed the title to [Solved] Check wich ListView in use or selected?

Another approach if you would like :

#include <GUIConstants.au3>
#include <StructureConstants.au3>

GUICreate("Form1", 590, 399, 589, 289)
Global $Button1 = GUICtrlCreateButton("Button1", 64, 272, 187, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Button2 = GUICtrlCreateButton("Button2", 320, 272, 195, 25)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $List1 = GUICtrlCreateListView("First  ", 64, 56, 185, 175)
Global $List2 = GUICtrlCreateListView("Second", 312, 64, 185, 175)
GUISetState(@SW_SHOW)

Local $idItem1 = GUICtrlCreateListViewItem("item1", $List1)
Local $idItem2 = GUICtrlCreateListViewItem("item2", $List1)
Local $idItem3 = GUICtrlCreateListViewItem("item3", $List1)
Local $idItem4 = GUICtrlCreateListViewItem("item4", $List1)
Local $idItem5 = GUICtrlCreateListViewItem("item5", $List1)

Local $idItem21 = GUICtrlCreateListViewItem("item1", $List2)
Local $idItem22 = GUICtrlCreateListViewItem("item2", $List2)
Local $idItem23 = GUICtrlCreateListViewItem("item3", $List2)
Local $idItem24 = GUICtrlCreateListViewItem("item4", $List2)
Local $idItem25 = GUICtrlCreateListViewItem("item5", $List2)

GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

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

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  If $tNMHDR.Code = $NM_CLICK Then
    Switch $tNMHDR.hwndFrom
      Case GUICtrlGetHandle($List1)
        ConsoleWrite("list 1" & @CRLF)
        GUICtrlSetState($Button1, $GUI_ENABLE)
        GUICtrlSetState($Button2, $GUI_DISABLE)
      Case GUICtrlGetHandle($List2)
        ConsoleWrite("list 2" & @CRLF)
        GUICtrlSetState($Button2, $GUI_ENABLE)
        GUICtrlSetState($Button1, $GUI_DISABLE)
    EndSwitch
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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