找回密码
 加入
搜索
查看: 12106|回复: 24

[AU3基础] [已解决]Checkbox复选框选中时怎么向ListView列表框写入数据

 火... [复制链接]
发表于 2011-6-18 22:00:16 | 显示全部楼层 |阅读模式
本帖最后由 minghui 于 2011-6-19 14:32 编辑



#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Global $n = 41
Local $Checkbox[$n][2], $wh = 30, $var = 265

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 621, 316, 192, 124)
$ListView1 = GUICtrlCreateListView("项目1|项目2|项目3", 4, 16, 245, 281)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 80)

For $i = 1 To $n - 1
    $varr = $wh * Int(($i - 1) / 4) + 16
        $Checkbox[$i][1] = GUICtrlCreateCheckbox("复选框 - " & $i, $var, $varr, 81, 17)
        $var +=88
        If $var = 617 Then $var = 265
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

如上面例子中,当选中复选框时向ListView列表框写入数据.取消勾选时删除数据
注明:复选框数量由配置文件决定生成多少个(10个或20个不等)

本帖子中包含更多资源

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

×
发表于 2011-6-18 22:36:09 | 显示全部楼层
论坛里有例子,去找找看
 楼主| 发表于 2011-6-18 22:55:28 | 显示全部楼层
刚搜索了一遍没找到,哎
发表于 2011-6-19 00:00:46 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
Opt("GUIOnEventMode",1)
Global $n = 41
Local $Checkbox[$n][2], $wh = 30, $var = 265

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 621, 316, 192, 124)
GUISetOnEvent(-3,"_Exit")
$ListView1 = GUICtrlCreateListView("项目1|项目2|项目3", 4, 16, 245, 281)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 80)
$hListView=GUICtrlGetHandle($ListView1)

For $i = 1 To $n - 1
    $varr = $wh * Int(($i - 1) / 4) + 16
        $Checkbox[$i][1] = GUICtrlCreateCheckbox("复选框 - " & $i, $var, $varr, 81, 17)
                GUICtrlSetOnEvent(-1,"_Check")
        $var +=88
        If $var = 617 Then $var = 265
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(10)
WEnd
        
Func _Exit()
        Exit
EndFunc

Func _Check()
        local $index_set,$index_get
        Switch GUICtrlRead(@GUI_CtrlId)
                case 1
                        $index_set=_GUICtrlListView_AddItem($hListView,"复选框数据-"&@GUI_CtrlId-3)
                        _GUICtrlListView_SetItemParam($hListView, $index_set, @GUI_CtrlHandle)
                Case 4
                        $index=_GUICtrlListView_FindParam($hListView,@GUI_CtrlHandle)
                        _GUICtrlListView_EnsureVisible($hListView, $index)
                         _GUICtrlListView_DeleteItem($hListView,$index)
        EndSwitch
                
EndFunc
发表于 2011-6-19 04:21:20 | 显示全部楼层
试试看,自己没有多少时间写代码的。Thanks for your shares!!!
发表于 2011-6-19 09:52:39 | 显示全部楼层
三笑大大,顶
发表于 2011-6-19 13:45:25 | 显示全部楼层
做个记号!日后用得上!
 楼主| 发表于 2011-6-19 14:29:12 | 显示全部楼层
回复 4# 3mile

谢谢 3MILE 问题解决了,如果写入的数据能以复选框的顺序来写入就好了
 楼主| 发表于 2011-6-19 15:32:05 | 显示全部楼层
回复 4# 3mile

还想麻烦你一下,数据如何往项目2,项目3写入数据呢 _GUICtrlListView_AddItem 这个函数好像不行啊!  只能往项目1写入数据
发表于 2011-6-19 15:47:44 | 显示全部楼层
回复 9# minghui
两个问题都很简单,如果你自己能多看看帮助一定可以自己解决的.
提示一下:
一.排序的问题我知道的有两种方法
    1.LISTVIEW的样式
    2.注册回调函数,每增加或删除时排序
    这里要注意一个问题,字符串的排序问题,建议用STRINGFORMAT解决
二.增加子数据的问题
    既然已经知道有_GUICtrlListView_AddItem函数,难道不会用_GUICtrlListView_AddSubItem函数?
相信你一定可以解决这个问题的!
 楼主| 发表于 2011-6-19 15:57:07 | 显示全部楼层
回复 10# 3mile

第二个问题找到了这个函数可以解决  _GUICtrlListView_AddArray  好像方便一些
第一个问题还在找方法,都是E文看不懂写起来就是麻烦,还得一边看一边网上去翻译
 楼主| 发表于 2011-6-19 16:20:44 | 显示全部楼层
_GUICtrlListView_AddArray 测试了下不行 排序有问题
发表于 2011-6-19 20:51:00 | 显示全部楼层
回复 12# minghui
嗯,字符串排序的确是比较麻烦.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
Global $n = 41
Local $Checkbox[$n][2], $wh = 30, $var = 265

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 621, 316, 192, 124)
GUISetOnEvent(-3, "_Exit")
$ListView1 = GUICtrlCreateListView("项目1|项目2|项目3", 4, 16, 245, 281, $LVS_SORTASCENDING)
GUICtrlSetOnEvent(-1, "Listview_Sort")
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 80)
$hListView = GUICtrlGetHandle($ListView1)
_GUICtrlListView_RegisterSortCallBack($hListView)
For $i = 1 To $n - 1
        $varr = $wh * Int(($i - 1) / 4) + 16
        $Checkbox[$i][1] = GUICtrlCreateCheckbox("复选框" & $i, $var, $varr, 81, 17)
        GUICtrlSetOnEvent(-1, "_Check")
        $var += 88
        If $var = 617 Then $var = 265
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(10)
WEnd

Func _Exit()
        Exit
EndFunc   ;==>_Exit

Func _Check()
        Local $index_set, $index_get
        Switch GUICtrlRead(@GUI_CtrlId)
                Case 1
                        $index_set = _GUICtrlListView_AddItem($hListView, "复选框数据-" & StringFormat("%02d", @GUI_CtrlId - 3))
                        _GUICtrlListView_SetItemParam($hListView, $index_set, @GUI_CtrlHandle)
                        For $i = 1 To 2
                                _GUICtrlListView_AddSubItem($hListView, $index_set, "第" & @GUI_CtrlId - 3 & "项第" & $i & "列子数据", $i)
                        Next
                Case 4
                        $index = _GUICtrlListView_FindParam($hListView, @GUI_CtrlHandle)
                        _GUICtrlListView_EnsureVisible($hListView, $index)
                        _GUICtrlListView_DeleteItem($hListView, $index)
        EndSwitch

EndFunc   ;==>_Check

Func Listview_Sort()
        _GUICtrlListView_SortItems($hListView, GUICtrlGetState($ListView1))
EndFunc   ;==>Listview_Sort
 楼主| 发表于 2011-6-21 01:32:19 | 显示全部楼层
回复 13# 3mile
谢谢3MILE

按你的思路如下面代码 我是这样写的,当选的软件越多,窗口就会闪动的原厉害. 有没有方法可以让窗口不闪动吗?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
Global $n = 41
Local $Checkbox[$n][2], $wh = 30, $var = 265

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 621, 316, 192, 124)
GUISetOnEvent(-3, "_Exit")
$ListView1 = GUICtrlCreateListView("项目1|项目2|项目3", 4, 16, 245, 281)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 80)

For $i = 1 To $n - 1
        $varr = $wh * Int(($i - 1) / 4) + 16
        $Checkbox[$i][1] = GUICtrlCreateCheckbox("复选框 - " & $i, $var, $varr, 81, 17)
        GUICtrlSetOnEvent(-1, "_Check")
        $var += 88
        If $var = 617 Then $var = 265
Next

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        Sleep(10)
WEnd

Func _Exit()
        Exit
EndFunc   ;==>_Exit

Func _Check()
        $e = 1
        _GUICtrlListView_DeleteAllItems($ListView1)
        For $i = 1 To $n - 1
                If GUICtrlRead($Checkbox[$i][1]) = 1 Then
                        GUICtrlCreateListViewItem('[' & StringFormat("%02d", $e) & '] ' & "复选框-" & $i & "|第" & $i & "项第1列子数据|第" & $i & "项第2列子数据", $ListView1)
                    $e += 1
                EndIf
        Next
EndFunc   ;==>_Check
发表于 2011-6-21 09:41:39 | 显示全部楼层
菜鸟 急需金币 回复下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 18:30 , Processed in 0.080646 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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