【已解决】GUICtrlCreateListViewItem如何指定位置?
本帖最后由 vigiles 于 2014-2-27 11:38 编辑GUICtrlCreateListView创建列表视图(ListView)控件。
GUICtrlCreateListViewItem默认在最后一行插入新的条目。但我希望在最上面插入,费时颇多,不能达成。请指教!
使用_GUICtrlListView_InsertItem结合_GUICtrlListView_AddSubItem可以在最上面插入条目,但此条目不能通过GUICtrlRead读取到条目内数据。_GUICtrlListView_GetItemTextString、_GUICtrlListView_GetItemText也是无用。 没见到你的代码。测试完全没有你所说的问题#include <GuiListView.au3>
GUICreate('')
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState(@SW_SHOW)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertItem($hListView, "Item 1", 0)
_GUICtrlListView_InsertItem($hListView, "Item 2", 1)
MsgBox(0, '', '插到顶部')
_GUICtrlListView_InsertItem($hListView, "插到顶部", 0)
MsgBox(0, _GUICtrlListView_GetItemText($hListView, 0), _GUICtrlListView_GetItemTextString($hListView, 0))
Do
Until GUIGetMsg() = -3
GUIDelete()
斑竹厉害,学习 本帖最后由 vigiles 于 2014-2-27 11:37 编辑
斑竹厉害,学习
wilask 发表于 2014-2-27 09:30 http://www.autoitx.com/images/common/back.gif
没见到你的代码。测试完全没有你所说的问题
afan 发表于 2014-2-27 01:08 http://www.autoitx.com/images/common/back.gif
谢过两位,我想要的已经实现了:
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
AutoItSetOption("GUIOnEventMode", 1)
; 创建 GUI
GUICreate("添加列表视图子项", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "funcGUISetOnEvent")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;监听事件,要紧跟在控件后面(事件类型,回调函数)
$hListView = GUICtrlCreateListView("列1 |列2 |列3 |", 2, 2, 394, 268)
; 添加项目
_GUICtrlListView_InsertItem($hListView, "第一此插入行", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "一2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "一3", 2)
_GUICtrlListView_InsertItem($hListView, "第二次插入行", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "2-2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "2-3", 2)
_GUICtrlListView_InsertItem($hListView, "第三次插入", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "三-1", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "三-2", 2)
GUISetState(@SW_SHOW)
While 1
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = DllStructGetData($tNMHDR, 2)
Local $iCode = DllStructGetData($tNMHDR, 3)
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
$Index = _GUICtrlListView_GetSelectedIndices($hListView) ;行标示符
$L_Name = _GUICtrlListView_GetItemTextString($hListView, Number($Index)) ;整行内容。_GUICtrlListView_GetItemText为指定行第一个单元格内容
;$lsid = GUICtrlRead($hListView) ;选中行的标识符,读不到
;$strL = GUICtrlRead($Index) ;整行文本内容,读不到
MsgBox(0, "", "选择的行标示符:" & $Index & @CRLF & "整行文本:" & $L_Name)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func funcGUISetOnEvent()
Exit
EndFunc
页:
[1]