关于Guictrllistview_addarray()的问题?
首先,将以下的代码中的组 去掉,可以将 数组 添加到 列表项的 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,$iI
For $iI = 0 To UBound($aItems) - 1
$aItems[$iI] = "Item " & $iI
Next
_GUICtrlListView_AddArray($hListView, $aItems)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main 回复 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,$iI
For $iI = 0 To UBound($aItems) - 1
$aItems[$iI] = "Item " & $iI & "-0"
$aItems[$iI] = "Item " & $iI & "-1"
$aItems[$iI] = "Item " & $iI & "-2"
Next
_GUICtrlListView_AddArray($hListView, $aItems)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main 回复 2# newuser
我的描述有问题吗? 第0列用普通办法好像没法加,可以试试建一个dummy放在第0列 回复 4# netegg
谢谢老大,现在正学习帮助中的函数部分,很多现成的例子看来不现成,还得实践呀! 回复 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, $iI
For $iI = 0 To UBound($aItems) - 1
$aItems[$iI] = "Item " & $iI & "-0"
$aItems[$iI] = "Item " & $iI & "-1"
$aItems[$iI] = "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 本帖最后由 newuser 于 2010-11-15 16:44 编辑
回复 6# 3mile
是的,想学习将数组加到ListView的指定位置,但是不想覆盖由来ListViewItem的内容,但是上面的例子覆盖了原来的内容.
页:
[1]