找回密码
 加入
搜索
查看: 2792|回复: 6

[AU3基础] 关于Guictrllistview_addarray()的问题?

[复制链接]
发表于 2010-11-12 09:43:29 | 显示全部楼层 |阅读模式
首先,将以下的代码中的  组 去掉,可以将 数组 添加到 列表项的 0 列,我想问的是不去掉 组,能否将 数组 添加到列表项的第 1 列 上.
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
    
    GUICreate("ListView Insert Group", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
        _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; 加载图象或颜色块
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
        ; _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16) 列表句柄,颜色,宽,高
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_AddBitmap($hImage,"D:\zgk_2010\autoit\CommonDataArea\close_1.bmp");也可以添加BMP图标
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; 为列表视图控件分配100项目内存---新学到的
        _GUICtrlListView_SetItemCount($hListView, 5000)

    ; 添加列表项
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 0)
        ;正如本例,如果ListView设置了3个列,那么最初只设置了0项第0列,想再后续添加后续列,那么就添加 子项,这或许就是二者的不同吧!
        ;最后的0是 images list的序列号,也是从0开始,上面为ImageList设置了3个项,即从 0 - 2
    _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)

    ; Build groups
    _GUICtrlListView_EnableGroupView($hListView);允许或禁止 列表项 作为组显示
    _GUICtrlListView_InsertGroup($hListView, -1, 1, "Group 1-新建立的第1个Group的头标题")
    _GUICtrlListView_InsertGroup($hListView, -1, 2, "Group 2",1)
        ;-1表示组被添加到列表的尾部
        ;最后的1表示  组的头标题-Group2  居中显示
        _GUICtrlListView_InsertGroup($hListView,-1,3,"Group3",2)
    _GUICtrlListView_SetItemGroupID($hListView, 0, 1);0是  列表项的索引 ,1 是组的索引
    _GUICtrlListView_SetItemGroupID($hListView, 1, 2)
    _GUICtrlListView_SetItemGroupID($hListView, 2, 3)
        
        ;以下是插入1个数组
         ; One column load
    Local $aItems[5000][1],$iI
    For $iI = 0 To UBound($aItems) - 1
        $aItems[$iI][0] = "Item " & $iI
    Next
    _GUICtrlListView_AddArray($hListView, $aItems)


           
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
 楼主| 发表于 2010-11-12 10:04:06 | 显示全部楼层
回复 1# newuser
改了一下,还是不满意,0行0列怎么不显示?
#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
    
    GUICreate("ListView Insert Group", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
        _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; 加载图象或颜色块
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
        ; _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16) 列表句柄,颜色,宽,高
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_AddBitmap($hImage,"D:\zgk_2010\autoit\CommonDataArea\close_1.bmp");也可以添加BMP图标
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; 为列表视图控件分配100项目内存---新学到的
        _GUICtrlListView_SetItemCount($hListView, 5003)

    ; 添加列表项
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 0)
        ;正如本例,如果ListView设置了3个列,那么最初只设置了0项第0列,想再后续添加后续列,那么就添加 子项,这或许就是二者的不同吧!
        ;最后的0是 images list的序列号,也是从0开始,上面为ImageList设置了3个项,即从 0 - 2
    _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)

    ; Build groups
    _GUICtrlListView_EnableGroupView($hListView);允许或禁止 列表项 作为组显示
    _GUICtrlListView_InsertGroup($hListView, -1, 1, "Group 1-新建立的第1个Group的头标题")
    _GUICtrlListView_InsertGroup($hListView, -1, 2, "Group 2",1)
        ;-1表示组被添加到列表的尾部
        ;最后的1表示  组的头标题-Group2  居中显示
        _GUICtrlListView_InsertGroup($hListView,-1,3,"Group3",2)
    _GUICtrlListView_SetItemGroupID($hListView, 0, 1);0是  列表项的索引 ,1 是组的索引
    _GUICtrlListView_SetItemGroupID($hListView, 1, 2)
    _GUICtrlListView_SetItemGroupID($hListView, 2, 3)
        
        ;以下是插入1个数组
         ; One column load
    Local $aItems[5000][3],$iI
    For $iI = 0 To UBound($aItems) - 1
        $aItems[$iI][0] = "Item " & $iI & "-0"
                $aItems[$iI][1] = "Item " & $iI & "-1"
                $aItems[$iI][2] = "Item " & $iI & "-2"
    Next
    _GUICtrlListView_AddArray($hListView, $aItems)


           
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
 楼主| 发表于 2010-11-15 13:49:17 | 显示全部楼层
回复 2# newuser
我的描述有问题吗?
发表于 2010-11-15 14:10:07 | 显示全部楼层
第0列用普通办法好像没法加,可以试试建一个dummy放在第0列
 楼主| 发表于 2010-11-15 15:26:27 | 显示全部楼层
回复 4# netegg
谢谢老大,现在正学习帮助中的函数部分,很多现成的例子看来不现成,还得实践呀!
发表于 2010-11-15 16:31:00 | 显示全部楼层
回复 1# newuser
不大理解你表达的意思.
是将数组加入LISTVIEW的分组里?
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
;~     Local $hListView
    GUICreate("ListView Insert Group", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    ;_GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; 加载图象或颜色块
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    ; _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16) 列表句柄,颜色,宽,高
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_AddBitmap($hImage, "D:\zgk_2010\autoit\CommonDataArea\close_1.bmp");也可以添加BMP图标
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; 为列表视图控件分配100项目内存---新学到的
    _GUICtrlListView_SetItemCount($hListView, 5003)

    ; 添加列表项
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 0)
    ;正如本例,如果ListView设置了3个列,那么最初只设置了0项第0列,想再后续添加后续列,那么就添加 子项,这或许就是二者的不同吧!
    ;最后的0是 images list的序列号,也是从0开始,上面为ImageList设置了3个项,即从 0 - 2
    _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)

    ;以下是插入1个数组
    ; One column load
    Local $aItems[30][3], $iI
    For $iI = 0 To UBound($aItems) - 1
        $aItems[$iI][0] = "Item " & $iI & "-0"
        $aItems[$iI][1] = "Item " & $iI & "-1"
        $aItems[$iI][2] = "Item " & $iI & "-2"
    Next
    _GUICtrlListView_AddArray(GUICtrlGetHandle($hListView), $aItems)


    _GUICtrlListView_EnableGroupView($hListView);允许或禁止 列表项 作为组显示
    _GUICtrlListView_InsertGroup($hListView, -1, 1, "Group 1-新建立的第1个Group的头标题")
    _GUICtrlListView_InsertGroup($hListView, -1, 2, "Group 2", 1)
    ;-1表示组被添加到列表的尾部
    ;最后的1表示  组的头标题-Group2  居中显示
    _GUICtrlListView_InsertGroup($hListView, -1, 3, "Group3", 2)
    For $i=0 To 2
        For $n=0 To 9
            _GUICtrlListView_SetItemGroupID($hListView, $i*10+$n, $i+1);0是  列表项的索引 ,1 是组的索引
        Next
    Next

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
 楼主| 发表于 2010-11-15 16:35:23 | 显示全部楼层
本帖最后由 newuser 于 2010-11-15 16:44 编辑

回复 6# 3mile
是的,想学习将数组加到ListView的指定位置,但是不想覆盖由来ListViewItem的内容,但是上面的例子覆盖了原来的内容.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 18:40 , Processed in 0.084850 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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