找回密码
 加入
搜索
查看: 12867|回复: 16

[GUI管理] 求教lisview下带checkbox样式下,如何选中checkbox后高亮!

 火.. [复制链接]
发表于 2014-7-12 20:25:10 | 显示全部楼层 |阅读模式
遇到两个问题,求高手指导。
我用的代码中没有用到句柄来做,有相关的帖子通过句柄来判断实现,可是发现有点卡顿,想实现点击checkbox后本行业高亮,始终无法实现,帮忙看看代码。
另一个问题是如何计算选中的checkbox相应的第一列的值的字符串或者数组,
求帮助,不盛感激!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
$Form1 = GUICreate("Form1", 800, 600)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Local $iExListViewStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)
$ListView1 = GUICtrlCreateListView("工单编号|姓名|备注", 112, 72, 569, 409, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), $iExListViewStyle)
GUICtrlSetFont(-1, 11, 800, 0, "微软雅黑")
GUICtrlCreateListViewItem("1|张三|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("2|李四|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("3|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("4|张三|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("5|李四|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("6|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("7|张三|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("8|李四|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("9|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("10|张三|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("11|李四|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("12|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("13|张三|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("14|李四|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("15|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
GUICtrlCreateListViewItem("16|王五|欢迎使用 AutoIt v3 中文版 !", $ListView1)
_GUICtrlListView_SetColumnWidth($ListView1, 2, 435)
$WorkListViewContextMenu = GUICtrlCreateContextMenu($ListView1)
$WorkExAllBtn = GUICtrlCreateMenuItem("全选", $WorkListViewContextMenu)
GUICtrlCreateMenuItem("", $WorkListViewContextMenu)
$WorkExNoAllBtn = GUICtrlCreateMenuItem("全不选", $WorkListViewContextMenu)
GUICtrlCreateMenuItem("", $WorkListViewContextMenu)
$WorkExOppositeBtn = GUICtrlCreateMenuItem("反选", $WorkListViewContextMenu)
$Button1 = GUICtrlCreateButton("输出选中的编号数组", 112, 504, 145, 41)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateInput("", 264, 505, 417, 38)
GUICtrlSetFont(-1, 17, 400, 0, "微软雅黑")
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $ilParam)

        Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
        Local $tagNMHDR = DllStructCreate("int;int;int", $ilParam)
        If @error Then Return $GUI_RUNDEFMSG
        $IDFrom = DllStructGetData($tagNMHDR, 2)
        $Event = DllStructGetData($tagNMHDR, 3)
        $tagNMHDR = 0
        Switch $IDFrom;选择产生事件的控件

                Case $ListView1

                        Switch $Event; 选择产生的事件

                                Case $NM_CLICK ; 左击
;~                                     ...
                                        ;MsgBox($MB_SYSTEMMODAL, "消息", "项目数: " & _GUICtrlListView_GetItemCount($ListView1))
                                        
                                        $Index = _GUICtrlListView_GetSelectedIndices($ListView1)
                                        If Not StringLen($Index) Then Return ;这里用以判断是否选定了ListViewItem
                                        $iID = _GUICtrlListView_GetItemText($ListView1, Number(_GUICtrlListView_GetSelectedIndices($ListView1)), 0)
                                        If _GUICtrlListView_GetItemChecked($ListView1, $Index) = False Then
                                                _GUICtrlListView_SetItemChecked($ListView1, $Index)
                                                ;_GUICtrlListView_SetItemSelected($ListView1, $Index)
                                        Else
                                                If _GUICtrlListView_GetItemChecked($ListView1, $Index) = True Then _GUICtrlListView_SetItemChecked($ListView1, $Index, False)
                                        EndIf
                                Case $NM_DBLCLK ; 双击全选checkbox
;~                                      ...
                                        ;If _GUICtrlListView_GetItemChecked($ListView1, -1) = False Then _GUICtrlListView_SetItemChecked($ListView1, -1, True)
                                Case $NM_RCLICK ; 右击
;~                                      ...
                        EndSwitch

        EndSwitch

        ;Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2014-7-12 20:29:54 | 显示全部楼层
顶下自己,这个功能是用在做数据库操作时,选中不需要的然后批量做删除操作!
发表于 2014-7-12 21:30:28 | 显示全部楼层
 楼主| 发表于 2014-7-12 23:35:43 | 显示全部楼层
谢A大,我去研究下!
发表于 2014-7-13 08:28:41 | 显示全部楼层
如果下图是你要的效果,那根本不需要用事件触发模式那么复杂。
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

Global $gu_Demo__Form1 = GUICreate('Demo', 489, 361, -1, -1)
Global $gu_Demo__ListView1 = GUICtrlCreateListView('', 16, 16, 449, 321, -1, _
                BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))

_Demo__Main()
Exit

Func _Demo__Main()
        
        _GUICtrlListView_AddColumn($gu_Demo__ListView1, '', 40)
        _GUICtrlListView_AddColumn($gu_Demo__ListView1, '姓名', 100)
        _GUICtrlListView_AddColumn($gu_Demo__ListView1, '年龄', 100)
        _GUICtrlListView_AddColumn($gu_Demo__ListView1, '性别', 100)
        _GUICtrlListView_AddColumn($gu_Demo__ListView1, '成绩', 100)
        
        GUISetState(@SW_SHOW, $gu_Demo__Form1)
        
        Local $a_ListviewData = _Demo__GetDataList()
        _Demo__DisplayData($a_ListviewData)
        
        Local $nMsg
        While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                Exit

                EndSwitch
                
                For $i = 1 To $a_ListviewData[0][0]
                        If $nMsg = $a_ListviewData[$i][0] Then
                                If _GUICtrlListView_GetItemChecked($gu_Demo__ListView1, $i - 1) Then
                                        GUICtrlSetColor($a_ListviewData[$i][0], 0xff0000)
                                Else
                                        GUICtrlSetColor($a_ListviewData[$i][0], 0x000000)
                                EndIf
                        EndIf
                Next
        WEnd
        
EndFunc   ;==>_Demo__Main

Func _Demo__GetDataList()
        Local Const $N = 6
        Local $a_Data[][$N] = [['', 'Name', 'Age', 'Sex', 'Score'], _
                        [0, '张伟', '21', '男', '87'], _
                        [0, '李虎', '23', '男', '73'], _
                        [0, '王媛', '21', '女', '85'], _
                        [0, '赵明', '22', '男', '91'], _
                        [0, '刘琦', '20', '女', '97']]
        $a_Data[0][0] = UBound($a_Data, 1) - 1
        Return $a_Data
EndFunc   ;==>_Demo__GetDataList

Func _Demo__DisplayData(ByRef $a_Data)
        _GUICtrlListView_BeginUpdate($gu_Demo__ListView1)
        _GUICtrlListView_DeleteAllItems($gu_Demo__ListView1)
        
        Local $i, $j, $ts
        For $i = 1 To UBound($a_Data, 1) - 1
                $ts = ''
                For $j = 1 To UBound($a_Data, 1) - 2
                        $ts &= '|' & $a_Data[$i][$j]
                Next
                $a_Data[$i][0] = GUICtrlCreateListViewItem($ts, $gu_Demo__ListView1)
        Next
        
        _GUICtrlListView_EndUpdate($gu_Demo__ListView1)
EndFunc   ;==>_Demo__DisplayData

本帖子中包含更多资源

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

×
 楼主| 发表于 2014-7-13 12:52:53 | 显示全部楼层
回复 5# skyfree


    谢谢!效果基本可以达到,可是我用的sqlite数据量大了了这种的不知道是否合适?!
 楼主| 发表于 2014-7-13 19:00:30 | 显示全部楼层
哪位大大还能给出其他方案啊?
发表于 2014-7-13 23:03:06 | 显示全部楼层
来踩个点嘿嘿
发表于 2014-7-14 09:18:21 | 显示全部楼层
回复 6# hollandmfq


    你要是几万、几十万条数据还是用事件触发模式吧。。。。。几千条无所谓。
发表于 2014-7-14 10:18:33 | 显示全部楼层
很不错~~我去研究下!
发表于 2014-7-14 11:08:11 | 显示全部楼层
学习来的,谢谢高手们
 楼主| 发表于 2014-7-15 08:58:09 | 显示全部楼层
回复 9# skyfree


    谢谢风行者!感激!
发表于 2014-7-15 09:02:21 | 显示全部楼层
回复 12# hollandmfq


    我是我,风行是风行。。。别弄混了。。。。。。我是之前帮风行的视频发了个广告,别弄混我们俩。。。。。。。。。
 楼主| 发表于 2014-7-15 13:51:07 | 显示全部楼层
回复 13# skyfree


    额,呵呵!不好意思!
发表于 2014-7-16 15:38:21 | 显示全部楼层
支持以下,赚金币
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 00:07 , Processed in 0.086763 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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