[已解决]如何让ListView创建的复选框设置为不可选状态?
本帖最后由 雨林GG 于 2011-7-20 15:10 编辑对于文件大小为 0 b的文件复选框设置为不可选状态!~~
实在搞不懂包含文件中那些常量是什么意思 !!!
附源码!
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $aLog, $FileCount = 0
_Filelist(@WindowsDir & "\*.log", $aLog)
ReDim $aLog[$FileCount]
;_ArrayDisplay($aLog)
Dim $Listem[$FileCount]
$MainForm = GUICreate("Form1", 550, 450, -1, -1)
$hImage = _GUIImageList_Create(24, 24, 5, 3, 4)
$SoftListView = GUICtrlCreateListView(" 文件|大小", 0, 21, 549, 343);, $LVS_ICON, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetImageList($SoftListView, $hImage, 0)
_GUICtrlListView_SetExtendedListViewStyle($SoftListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;, $LVS_EX_SIMPLESELECT
_GUICtrlListView_SetColumnWidth($SoftListView, 0, 440) ;软件名称
_GUICtrlListView_SetColumnWidth($SoftListView, 1, 100) ;
For $i = 0 To $FileCount - 1
$Listem[$i] = GUICtrlCreateListViewItem($aLog[$i] & "|" & $aLog[$i], $SoftListView)
If $aLog[$i] <> "0 b" Then
_GUICtrlListView_SetItemChecked($SoftListView, $i)
Else
;这里设置为不可选状态 <-----------------------------------------------
;_GUICtrlListView_SetItemState($SoftListView, $i, $LVIS_CUT, $LVIS_CUT)
EndIf
Next
GUISetState(@SW_SHOW)
Do
Until GUIGetMsg() = -3
Func _FileList($SearchLog, ByRef $Array)
; 显示当前目录中所有文件的文件名.
$search = FileFindFirstFile($SearchLog)
; 检查搜索是否成功
If $search = -1 Then Return
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$Array[$FileCount] = $file
$Array[$FileCount] = MylBytes(FileGetSize(@WindowsDir & "\" & $file))
$FileCount += 1
ReDim $Array[$FileCount + 1]
WEnd
; 关闭搜索句柄
FileClose($search)
EndFunc ;==>_FileList
Func MylBytes($lBytes)
If $lBytes < 1024 Then
Return ($lBytes & " b")
ElseIf $lBytes < 1048576 Then
Return Int(($lBytes / 1024)) & " K"
ElseIf $lBytes < 536870912 Then
Return Round($lBytes / 1024 / 1024, 2) & " M"
Else
Return Round($lBytes / (1024 ^ 2) / 1024, 2) & " G"
EndIf
EndFunc ;==>MylBytes
狠琢磨了半天楼主的意思,难道是要这样的效果?
至于包含文件中定义好的常量,无非是达到所要效果需要定义的参数,活学活用便行啦。
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <Array.au3>
Global $aLog, $FileCount = 0
_Filelist(@WindowsDir & "\*.log", $aLog)
ReDim $aLog[$FileCount]
;_ArrayDisplay($aLog)
Dim $Listem[$FileCount]
$MainForm = GUICreate("Form1", 550, 450, -1, -1)
$hImage = _GUIImageList_Create(24, 24, 5, 3, 4)
$SoftListView = GUICtrlCreateListView(" 文件|大小", 0, 21, 549, 343);, $LVS_ICON, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetImageList($SoftListView, $hImage, 0)
_GUICtrlListView_SetExtendedListViewStyle($SoftListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;, $LVS_EX_SIMPLESELECT
_GUICtrlListView_SetColumnWidth($SoftListView, 0, 440) ;软件名称
_GUICtrlListView_SetColumnWidth($SoftListView, 1, 100) ;
For $i = 0 To $FileCount - 1
$Listem[$i] = GUICtrlCreateListViewItem($aLog[$i] & "|" & $aLog[$i], $SoftListView)
_GUICtrlListView_SetItemState($SoftListView, $i, $LVIS_CUT, $LVIS_CUT)
Next
GUISetState(@SW_SHOW)
Do
Until GUIGetMsg() = -3
Func _FileList($SearchLog, ByRef $Array)
; 显示当前目录中所有文件的文件名.
$search = FileFindFirstFile($SearchLog)
; 检查搜索是否成功
If $search = -1 Then Return
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$Array[$FileCount] = $file
$Array[$FileCount] = MylBytes(FileGetSize(@WindowsDir & "\" & $file))
$FileCount += 1
ReDim $Array[$FileCount + 1]
WEnd
; 关闭搜索句柄
FileClose($search)
EndFunc ;==>_FileList
Func MylBytes($lBytes)
If $lBytes < 1024 Then
Return ($lBytes & " b")
ElseIf $lBytes < 1048576 Then
Return Int(($lBytes / 1024)) & " K"
ElseIf $lBytes < 536870912 Then
Return Round($lBytes / 1024 / 1024, 2) & " M"
Else
Return Round($lBytes / (1024 ^ 2) / 1024, 2) & " G"
EndIf
EndFunc ;==>MylBytes
回复 2# 502762378
兄弟好像 只是 把我 注释掉的东西 给加上去了吧?!
不可选 状态 类似于! $GUI_DISABLE, 这里用的 $LVIS_CUT 虽类似,但依然 可选择! lv的复选不可选状态,记得论坛里有,楼主好好搜搜,实在想不起来标题了 搜到这个!<如何使listview里面的项变成灰色,也就是不可用状态【已解决】>
http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&pid=270257&ptid=22222
但没有复选框,改了下风格也不行! 回复 5# 雨林GG
不是这个,实在想不起来标题是什么了,p侠写过一个 本帖最后由 雨林GG 于 2011-7-20 14:48 编辑
回复 6# netegg
终于找到~^
『 UDF 函数 』 » ListView UDF - ListView消息扩展
http://www.autoitx.com/forum.php?mod=viewthread&tid=13175&highlight=
谢谢你了!~ 也感谢伟大的P版 ~
页:
[1]