找回密码
 加入
搜索
查看: 3913|回复: 3

[GUI管理] 【已解决】GUICtrlCreateListViewItem如何指定位置?

[复制链接]
发表于 2014-2-26 21:51:45 | 显示全部楼层 |阅读模式
本帖最后由 vigiles 于 2014-2-27 11:38 编辑

GUICtrlCreateListView创建列表视图(ListView)控件。
GUICtrlCreateListViewItem默认在最后一行插入新的条目。但我希望在最上面插入,费时颇多,不能达成。请指教!




使用_GUICtrlListView_InsertItem结合_GUICtrlListView_AddSubItem可以在最上面插入条目,但此条目不能通过GUICtrlRead读取到条目内数据。_GUICtrlListView_GetItemTextString、_GUICtrlListView_GetItemText也是无用。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-2-27 01:08:10 | 显示全部楼层
没见到你的代码。测试完全没有你所说的问题
#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()
发表于 2014-2-27 09:30:50 | 显示全部楼层
斑竹厉害,学习
 楼主| 发表于 2014-2-27 11:36:30 | 显示全部楼层
本帖最后由 vigiles 于 2014-2-27 11:37 编辑
斑竹厉害,学习
wilask 发表于 2014-2-27 09:30


没见到你的代码。测试完全没有你所说的问题
afan 发表于 2014-2-27 01:08



        谢过两位,我想要的已经实现了:


#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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 13:17 , Processed in 0.080081 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表