[已解决]询问关于ListView事件产生的Item内容没法获取的问题
本帖最后由 techshi 于 2013-10-30 08:52 编辑大侠们,问一下关于ListView的简单的问题。
点击一个按钮在ListView里面添加内容,我点击另外一个按钮想获取刚刚点击产生的ListView 里面的内容却没法获得Item的Index值,Index值一直是0,我想问一下有什么方法可以获得呢?#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 287, 240, 401, 213)
$hListView = GUICtrlCreateListView("", 16, 16, 250, 150)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
$Button1 = GUICtrlCreateButton("Button1", 72, 192, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 168, 192, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
Case $Button2
$iIndex1 = GUICtrlRead($hListView)
MsgBox(0, '项目文本:', $iIndex1)
EndSwitch
WEnd 回复 1# techshi
GuiCtrlRead 只能读取 GuiCtrlCreateListViewItem 添加的控件值。
你的代码可以这样读取选中的文本。 Case $Button2
$iIndex1 = _GUICtrlListView_GetItemText($hListView, Number(_GUICtrlListView_GetSelectedIndices($hListView)))
MsgBox(0, '项目文本:', $iIndex1) 谢谢,user3000,问题已解决。 遇到同样的问题了,感谢指教! 问题已经解决了,非常感谢大家! 大侠,还请指导下,0的问题又是如何解决的呢?在listview没有选择item的时候,Number(_GUICtrlListView_GetSelectedIndices($hListView)) = 0
页:
[1]