【已解决】ListView项移动问题
本帖最后由 ybbihsse 于 2011-1-3 22:23 编辑如题,怎么把焦点移动到ListView列表项指定的项上
例如:ListView列中有140项数据,指定把焦点移到120项上
注:焦点没有在ListView控件上
答案在9楼 _GUICtrlListView_SetItemFocused 回复 2# netegg
这个要怎么用呀,为什么运行了,只是虚框上第二项上呀,而不是像鼠标点中有蓝底呀#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $hListView
GUICreate("ListView Set Item Focused", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
; Add columns
_GUICtrlListView_AddColumn($hListView, "Column 1", 100)
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
; Focus item 2
_GUICtrlListView_SetItemFocused($hListView, 1)
MsgBox(4160, "Information", "Item 2 Focused: " & _GUICtrlListView_GetItemFocused($hListView, 1))
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
怎么样才能实现上图的效果呀 _GUICtrlListView_SetItemSelect 回复 4# netegg
呵呵,不行耶,能不能给个小小的例子让我参考下呀!!! _GUICtrlListView_SetItemFocused($hListView, 1)
MsgBox(4160, "Information", "Item 2 Focused: " & _GUICtrlListView_GetItemFocused($hListView, 1))这两行改成
_GUICtrlListView_SetItemSelected($hListView, 1)
MsgBox(4160, "Information", "Item 2 Focused: " & _GUICtrlListView_GetItemSelected($hListView, 1))看看 回复 6# netegg
可以是可以了,但是要是项目有好几百行,就会出现有滚动条,焦点上去了,但滚动条不会跟着滚~~~ _GUICtrlListView_EnsureVisible($hWnd, $iIndex[, $fPartialOK = False]) 回复 8# netegg
不行,加上去没反应 本帖最后由 netegg 于 2011-1-3 20:51 编辑
回复 9# ybbihsse #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $hListView
GUICreate("ListView Set Item Focused", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
; Add columns
_GUICtrlListView_AddColumn($hListView, "Column 1", 100)
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)
For $i = 0 To 100
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", $i)
_GUICtrlListView_AddSubItem($hListView, $i, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, $i, "Row 1: Col 3", 2)
Next
; Focus item 2
_GUICtrlListView_SetItemSelected($hListView, 50)
_GUICtrlListView_EnsureVisible($hListView, 50)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main 回复 10# netegg
非常 感谢,真是个好人~~ 回复ybbihsse
netegg 发表于 2011-1-3 20:49 http://www.autoitx.com/images/common/back.gif
不错的技巧,收藏了。
页:
[1]