Listview中添加下拉框
似乎没法实现,不知有没其他方法实现类似的效果。网上有找到DataGrid添加ComboBox的方法,http://www.17aspx.com/uploads/allimg/100321/1_100321205000_1.gif,不过AU3也没有DataGrid控件 本帖最后由 netegg 于 2012-5-22 11:19 编辑
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Opt('GUIOnEventMode', 1)
Dim $hGUI = GUICreate('Test', 300, 200)
Dim $ListView = GUICtrlCreateListView('A|B|C', 0, 0, 300, 200, $LVS_NOSORTHEADER)
Dim $hListView = GUICtrlGetHandle($ListView)
Dim $hHeader = _GUICtrlListView_GetHeader($hListView)
Dim $hComboBox = _GUICtrlComboBox_Create($hListView, 'A|B|C|D', 0, 0)
Dim $hProc = DllCallbackRegister('_ListViewHandler', 'lresult', 'hwnd;uint;wparam;lparam')
Dim $pProc = DllCallbackGetPtr($hProc)
Dim $hListViewProc = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $pProc)
Dim $iItem = -1, $iSubitem = -1
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($hListView, 0, 100)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 100)
_GUICtrlListView_BeginUpdate($hListView)
For $i = 1 To 10
Local $iItem = _GUICtrlListView_AddItem($hListView, $i)
_GUICtrlListView_AddSubItem($hListView, $iItem, '', 1)
_GUICtrlListView_AddSubItem($hListView, $iItem, '', 2)
Next
_GUICtrlListView_EndUpdate($hListView)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Close')
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()
While 1
Sleep(10)
WEnd
Func _Close()
GUIDelete()
DllCallbackFree($hProc)
Exit
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNM = DllStructCreate($tagNMHDR, $ilParam)
Local $aSubHitTest
Local $aRect
Switch DllStructGetData($tNM, 'hWndFrom')
Case $hListView
If DllStructGetData($tNM, 'Code') = $LVN_HOTTRACK Then
$aSubHitTest = _GUICtrlListView_SubItemHitTest($hListView)
If $aSubHitTest > 0 Then
$aRect = _GUICtrlListView_GetSubItemRect($hListView, $aSubHitTest, $aSubHitTest)
_GUICtrlListView_SetItemText($hListView, $iItem, _GUICtrlComboBox_GetEditText($hComboBox), $iSubitem)
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
_WinAPI_MoveWindow($hComboBox, $aRect, $aRect, 100, 120)
_GUICtrlComboBox_SetCurSel($hComboBox, _GUICtrlComboBox_FindString($hComboBox, _GUICtrlListView_getItemText($hListView, $aSubHitTest, $aSubHitTest)))
_WinAPI_ShowWindow($hComboBox)
$iItem = $aSubHitTest
$iSubitem = $aSubHitTest
Else
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
EndIf
EndIf
Case $hHeader
Switch DllStructGetData($tNM, 'Code')
Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW
Return 1
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _ListViewHandler($hWnd, $iMsg, $iwParam, $ilParam)
Local $aRect
Switch $iMsg
Case $WM_HSCROLL, $WS_VSCROLL
If BitAND(_WinAPI_GetWindowLong($hComboBox, $GWL_STYLE), $WS_VISIBLE) Then
$aRect = _GUICtrlListView_GetSubItemRect($hListView, $iItem, $iSubitem)
_WinAPI_MoveWindow($hComboBox, $aRect, $aRect, 100, 120)
EndIf
EndSwitch
Return _WinAPI_CallWindowProc($hListViewProc, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc
嗯,改成$LVN_HOTTRACK比$nm_click好多了 可以利用 菜单的方法,鼠标移至这列时,菜单出现.
list自带的方法不知道有没有. 只要是为了显示数据,不是选择操作,所以用菜单不直观 似乎没法实现,不知有没其他方法实现类似的效果。
网上有找到DataGrid添加ComboBox的方法,,不过AU3也没有 ...
cxm23 发表于 2012-5-14 15:26 http://www.autoitx.com/images/common/back.gif
这种, 可以截获当点或双击Listview的Item时,就产生一个临时的Combo,当用户选了Combo里的值时,就把这个值赋予那个Item,然后就删除这个Combo,这样就可以实现这种效果了
当然也可以生成个Context菜单,当单击LV里的某个Item时,就在适当的位置显示这个右键菜单。 回复 4# happytc
应该是第一种
创建场景另做个界面只放combo就行了 回复 1# cxm23
不知道
GUICtrlCreateDummy ( )
行不? 回复cxm23
不知道
GUICtrlCreateDummy ( )
行不?
楼上风云 发表于 2012-5-14 22:09 http://www.autoitx.com/images/common/back.gif
怎么用这个达到楼主的目的?实在想不出来 看来没有回答了
我来抛个砖头,一定要引来玉女呀
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Misc.au3>
Global $fClick = False
Global $aLVClickInfo, $hTmpCombo = 0
Global $Dll = DllOpen("user32.dll")
Global $hGUI, $hListView, $sText, $hTmpCombo, $aLVRectInfo
Opt("GUICloseOnESC", 0)
Opt("MustDeclareVars", 1)
CreateGui()
Func CreateGui()
$hGUI = GUICreate("Test", 300, 200)
$hListView = _GUICtrlListView_Create($hGUI, "Col 0|Col 1|Col 2", 10, 10, 250, 200)
_GUICtrlListView_AddItem($hListView, "Item AA",0)
_GUICtrlListView_AddSubItem($hListView, 0, "Item AB", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Item AC", 2)
_GUICtrlListView_AddItem($hListView, "Item BA", 1)
_GUICtrlListView_AddItem($hListView, "Item CA", 2)
_GUICtrlListView_AddItem($hListView, "Item DA", 3)
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
If $hTmpCombo Then
If _IsPressed("0D", $Dll) Then
$sText = GUICtrlRead($hTmpCombo)
_GUICtrlListView_SetItemText($hListView, $aLVClickInfo, $sText, $aLVClickInfo)
GUICtrlDelete($hTmpCombo)
$hTmpCombo = 0
GUICtrlSetState($hListView, $GUI_ENABLE)
EndIf
If _IsPressed("1B", $Dll) Then
GUICtrlDelete($hTmpCombo)
$hTmpCombo = 0
GUICtrlSetState($hListView, $GUI_ENABLE)
EndIf
EndIf
If $fClick Then
$fClick = False
GUICtrlDelete($hTmpCombo)
Switch $aLVClickInfo
Case 0
$aLVRectInfo = _GUICtrlListView_GetItemRect($hListView, $aLVClickInfo, 2)
Case Else
$aLVRectInfo = _GUICtrlListView_GetSubItemRect($hListView, $aLVClickInfo, $aLVClickInfo)
EndSwitch
$hTmpCombo = GUICtrlCreateCombo("", $aLVRectInfo + 10, $aLVRectInfo + 10, 100, $aLVRectInfo - $aLVRectInfo)
GUICtrlSetData($hTmpCombo, "male|female|ladyboy")
GUICtrlSetState($hListView, $GUI_DISABLE)
GUICtrlSetState($hTmpCombo, BitOR($GUI_FOCUS, $GUI_ONTOP))
EndIf
WEnd
DllClose($Dll)
GUIDelete($hGUI)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
If $hTmpCombo Then Return $GUI_RUNDEFMSG
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then
$aLVClickInfo = _GUICtrlListView_SubItemHitTest($hListView)
If $aLVClickInfo <> -1 Then $fClick = True
EndIf
Return $GUI_RUNDEFMSG
EndFunc
本帖最后由 netegg 于 2012-5-15 07:54 编辑
回复 1# cxm23
grid可以用table来做,不过lz这种更像是listview 回复 9# netegg
table是什么? 本帖最后由 netegg 于 2012-5-15 09:40 编辑
回复 10# cxm23
表,也就是和你所说的grid更接近的一个玩意 回复 11# netegg
AU3有这个控件吗? 回复 12# cxm23
没,官方有个自制的 http://www.autoitscript.com/forum/topic/105814-table-udf/page__hl__table__fromsearch__1
找到了,不过似乎不是我想要的 回复 14# cxm23
这个倒是蛮漂亮的!谢谢分享
页:
[1]
2