本帖最后由 kk_lee69 于 2012-9-1 02:48 编辑
ListView 加上 CheckBox 风格后…CheckBox 如何变成单选的….
也就是說 選了一個項目後 CheckBOX 要打勾 然後 變成藍色高亮
如果換了項目 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 $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE,$LVS_EX_CHECKBOXES,$LVS_EX_SIMPLESELECT)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER,$LVS_EX_CHECKBOXES,$LVS_EX_SIMPLESELECT)
$ListView1 = GUICtrlCreateListView("A |B |", 8, 8, 300, 200, -1, $iExWindowStyle)
GUISetState(@SW_SHOW)
For $I = 1 To 10
GUICtrlCreateListViewItem($I, $ListView1)
Next
$hListView = GUICtrlGetHandle($Listview1)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iExListViewStyle)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ; $tagNMHDR - Contains information about a notification message
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case GuiCtrlGetHandle($ListView1)
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when user clicks an item with left mouse button
Local $aHit = _GUICtrlListView_HitTest($hListView)
If $aHit[5] Then _GUICtrlListView_ClickItem($hListView, $aHit[0])
If $aHit[0] <> -1 Then
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $Index = DllStructGetData($tInfo, "Index")
_GUICtrlListView_SetItemChecked($hListView, -1, False)
_GUICtrlListView_SetItemChecked($hListView, $Index)
Else
_GUICtrlListView_SetItemChecked($hListView, -1, False)
EndIf
EndSwitch
EndSwitch
EndFunc
|