请问如何获得treeview区域中用户点了哪个item?
代码如下:#region ### START Koda GUI section ### Form=c:\users\mason-home\desktop\外包人员管理软件单机版\公司管理.kxf
$Main = GUICreate("公司管理", 785, 584, 410, 124)
$MenuItem1 = GUICtrlCreateMenu("设置(&Y)")
$MenuItem3 = GUICtrlCreateMenuItem("用户管理", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenuItem("参数设置", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("帮助(&Z)")
$MenuItem5 = GUICtrlCreateMenuItem("关于", $MenuItem2)
$MenuItem6 = GUICtrlCreateMenuItem("退出", $MenuItem2)
$StatusBar = _GUICtrlStatusBar_Create($Main)
Dim $StatusBar_PartsWidth =
_GUICtrlStatusBar_SetParts($StatusBar, $StatusBar_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar, "", 0)
_GUICtrlStatusBar_SetText($StatusBar, "", 1)
$Tab1 = GUICtrlCreateTab(0, 0, 780, 540, $TCS_BUTTONS)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TabSheet2 = GUICtrlCreateTabItem("公司管理")
$TreeView1 = GUICtrlCreateTreeView(4, 28, 120, 505, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER))
$Group1 = GUICtrlCreateGroup("公司基本信息", 144, 28, 545, 505)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Button1", 696, 56, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 696, 139, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 696, 221, 75, 25)
$Button4 = GUICtrlCreateButton("Button4", 696, 304, 75, 25)
$TabSheet3 = GUICtrlCreateTabItem("人员管理")
$TabSheet4 = GUICtrlCreateTabItem("TabSheet4")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Tab1
$tabidx = GUICtrlRead($Tab1)
Select
Case $tabidx = 0
Case $tabidx = 1;公司管理标签
_getCompanyTree()
EndSelect
EndSwitch
WEnd
Func _getCompanyTree()
_GUICtrlTreeView_DeleteAll($TreeView1)
_GUICtrlTreeView_BeginUpdate($TreeView1)
Dim $addfld, $RS, $num
$num = _accessCountRecords($adSource, $coTable)
$hItem = _GUICtrlTreeView_Add($TreeView1, 0, "全部(" & $num & ")")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $adSource)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select 公司名称 From " & $coTable)
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
_GUICtrlTreeView_AddChild($TreeView1, $hItem, $RS.Fields(0).value)
$RS.movenext
WEnd
$RS.movenext
$RS.close
$addfld.Close
_GUICtrlTreeView_Expand($TreeView1)
_GUICtrlTreeView_EndUpdate($TreeView1)
EndFunc ;==>_getCompanyTree 本帖最后由 nmgwddj 于 2012-2-20 11:24 编辑
相同问题,我是用数组创建解决掉的。 这个代码能运行? 回复 3# afan
楼上的可能是这个意思,代码我贴上来了,其实我也很想实现,因为item是随机通过配置文件创建的,无法给固定的ID(通过数组方式可以,但是不想这么做),下面的例子可以获取到文本,但是每次点击都提示是上一次焦点项目的文本。苦恼!
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 367, 368, 279, 176)
$TreeView1 = GUICtrlCreateTreeView(16, 16, 337, 337)
For $i = 1 To 10
GUICtrlCreateTreeViewItem('TreeView_' & $i, $TreeView1)
Next
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom
Case $TreeView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;MsgBox(0, '', GUICtrlRead(GUICtrlRead($TreeView1)))
MsgBox(0, '', _GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
回复 4# nmgwddj
35行改为 Case $TVN_SELCHANGEDW 本帖最后由 nmgwddj 于 2012-2-20 14:02 编辑
回复 5# afan
请教 $TVN_SELCHANGEDW 事件是?修改后运行程序msgbox弹出一次,点击列表 先弹出上次的焦点,再弹出我点击的文字。
回复 6# nmgwddj
会有两次消息,第一次 GUICtrlRead($TreeView1) 为 0,第二次才是需要的,加个判断即可
If GUICtrlRead($TreeView1) > 0 Then Msgbox... 回复 7# afan
谢谢,那个通知具体是什么意思,能解释下吗? 回复 8# nmgwddj
字面解释就是选择项已改变… 懂了,谢谢指点,在帮助文档中看到例子了。 学习了{:face (356):}
页:
[1]