m904337 发表于 2010-12-24 12:55:14

有关GUICtrlCreateListViewItem问题

请教如何实现当滑鼠点选在项目1时,资料同时显示在$input1里面,原码如下~~谢谢#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg
   
    GUICreate("检视清单项目", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF); 将变更背景色彩

    $listview = GUICtrlCreateListView("栏位1|栏位2|栏位3", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("数值?", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem("项目2|栏位22|栏位23", $listview)
    $item2 = GUICtrlCreateListViewItem("项目1|栏位12|栏位13", $listview)
    $item3 = GUICtrlCreateListViewItem("项目3|栏位32|栏位33", $listview)
    $input1 = GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)   ; 允许即时拖曳动作
    GUISetState()
    GUICtrlSetData($item2, "|“项目1”")
    GUICtrlSetData($item3, "||“栏位33”")
    GUICtrlDelete($item1)

    Do
      $msg = GUIGetMsg()
      
      Select
            Case $msg = $button
                MsgBox(0, "检视清单项目", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "检视清单", "已点选=" & GUICtrlGetState($listview), 2)
      EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

m904337 发表于 2010-12-25 13:55:17

暂时想到个方法解决,但还是有点小问题,虽然选择项目后,再$input1会即时显示项目的内容,但会变成$input1无法变更资料,还需要想其法办法解决,源码如下#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg
   
    GUICreate("检视清单项目", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF); 将变更背景色彩

    $listview = GUICtrlCreateListView("栏位1|栏位2|栏位3", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("数值?", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem("项目2|栏位22|栏位23", $listview)
    $item2 = GUICtrlCreateListViewItem("项目1|栏位12|栏位13", $listview)
    $item3 = GUICtrlCreateListViewItem("项目3|栏位32|栏位33", $listview)
    $input1 = GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)   ; 允许即时拖曳动作
    GUISetState()
    GUICtrlSetData($item2, "|“项目1”")
    GUICtrlSetData($item3, "||“栏位33”")
    GUICtrlDelete($item1)

    Do
      $msg = GUIGetMsg()
      
      Select
            Case $msg = $button
                MsgBox(0, "检视清单项目", GUICtrlRead(GUICtrlRead($listview)), 2)
                        Case $listview
                                If _GUICtrlListView_GetItemSelected($listview , 0) = "True" Then
                                        GUICtrlSetData($input1, GUICtrlRead(GUICtrlRead($listview)))
                                Else
                                        If _GUICtrlListView_GetItemSelected($listview , 1) = "True" Then
                                        GUICtrlSetData($input1, GUICtrlRead(GUICtrlRead($listview)))
                                        EndIf
                                EndIf
            Case $msg = $listview
                MsgBox(0, "检视清单", "已点选=" & GUICtrlGetState($listview), 2)
      EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
页: [1]
查看完整版本: 有关GUICtrlCreateListViewItem问题