Netfox 发表于 2009-12-18 10:08:31

关于设置listview item选中问题

本帖最后由 Netfox 于 2009-12-18 11:19 编辑

请各位达达先看看下面两幅图片



       图一



    图二

我的代码如下:

Case $Button
                        $text = GUICtrlRead($input1)
                        $y = _GUICtrlListView_FindInText($ListView1, $text)                                               
                        _GUICtrlListView_EnsureVisible($ListView1, $y)
                        _GUICtrlListView_SetItemSelected($ListView1, $y)
                        MsgBox(0,"",_GUICtrlListView_GetItemSelected($ListView1, $y))

用_GUICtrlListView_SetItemSelected($ListView1, $y)已经选中了根据$y = _GUICtrlListView_FindInText($ListView1, $text)得到的item,用_GUICtrlListView_GetItemSelected($ListView1, $y))返回的信息已看到为TURE,我的目的是要像图二那样,选中所要的item,使它呈现出像用鼠标点它一样,有一块背景色。不知我把问题描述清楚没,希望各位帮帮忙。

C.L 发表于 2009-12-18 10:31:16

_GUICtrlListView_SetItemSelected($hWnd, $iIndex[, $fSelected = True[, $fFocused = False]])
默认$fFocused = False
设置$fFocused = true
_GUICtrlListView_SetItemSelected($ListView1, $y,True,True)

Netfox 发表于 2009-12-18 10:59:51

这样设置过了,没用呢。`。`

Netfox 发表于 2009-12-18 11:09:19

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 192, 114)
$Input1 = GUICtrlCreateInput("hp", 64, 32, 169, 21, 0,0)
;GUICtrlSetBkColor(-1,0xECE9D8)
$ListView1 = GUICtrlCreateListView("test|gg", 48, 96, 321, 73)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("pp",$ListView1)
GUICtrlCreateListViewItem("中国",$ListView1)
GUICtrlCreateListViewItem("hp",$ListView1)
$button1 = GUICtrlCreateButton("发送",168, 224, 177, 41)
GUICtrlSetState(-1, $GUI_FOCUS)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                case $Button1
                        $text =GUICtrlRead($input1)
                        $y=_GUICtrlListView_FindText($ListView1, $text)                               
                        _GUICtrlListView_SetItemSelected($ListView1, $y,True,True)
                        _GUICtrlListView_EnsureVisible($ListView1,$y)                                               
                       
        EndSwitch
WEnd
请看看,这样选中的效果如下图




也不达到用鼠标选中时的状态那样

Netfox 发表于 2009-12-18 11:19:14

已成功解决,呵呵。
页: [1]
查看完整版本: 关于设置listview item选中问题