找回密码
 加入
搜索
查看: 3603|回复: 7

[系统综合] 如何获取一个 Listbox 的行数和默认让它选择第一行

  [复制链接]
发表于 2014-1-15 20:19:37 | 显示全部楼层 |阅读模式
我向一个 Listbox 里写入了很多行内容,但不知道怎么获取总共写入了多少行,还有怎么让它默认就选择第一行;看帮助没有这种函数,只有对控件的  GuictrlRead 之类。。。
发表于 2014-1-15 22:24:06 | 显示全部楼层
回复 1# 不死帝国
你看到只是基本的帮助,还有“俗称为” UDF,功能更强大的“用户自定义函数”。
以下函数可以便捷实现你的目的。
_GUICtrlListBox_SetSel
_GUICtrlListBox_GetCount
发表于 2014-1-16 07:23:56 | 显示全部楼层
帮助里面找controlcommand看看呢
 楼主| 发表于 2014-1-16 16:17:18 | 显示全部楼层
谢谢大家;因为我看了又看帮助根本没有找着有关选择和获取Listbox的函数;UDF应该是自定义函数吧;又好像没有中文的帮助文档。。。
 楼主| 发表于 2014-1-16 17:07:36 | 显示全部楼层
回复 2# user3000


    #include <GUIListBox.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Desktop\Form1.kxf
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 64, 40, 337, 21)
$Button1 = GUICtrlCreateButton("...", 408, 40, 43, 21)
$Button2 = GUICtrlCreateButton("test", 488, 40, 75, 21)
$Button3 = GUICtrlCreateButton("返回", 488, 65, 75, 21)
$Progress1 = GUICtrlCreateProgress(64, 72, 390, 17)
$List1 = GUICtrlCreateList("", 64, 104, 550, 321)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUICtrlSetData($Input1,FileSelectFolder("选择一个文件夹",""))
                Case $Button2
                                If StringMid(GUICtrlRead($Input1),2,2) <> ":\" Then
                                        MsgBox(0,"提示","路径错误。")
                                Else
                                        GUICtrlSetData($List1,"")
                                        callback(GUICtrlRead($Input1))
                                        _GUICtrlListBox_SetSel($List1,1) ;为什么这样不能让Listbox默认选择第一条
                                EndIf
                Case $Button3
                        MsgBox(0,"",_GUICtrlListBox_GetCount($List1))
        EndSwitch
WEnd

;搜索指定目录下的所有文件与文件夹,不包括子目录
Func callback($path)
        Local $HWND = FileFindFirstFile($path & "\*.*")
        If $HWND = -1 Then Exit
       
        While 1
                Local $sFile = FileFindNextFile($HWND)
                If @error Then ExitLoop
                GUICtrlSetData($List1,$path & "\" & $sFile)
        WEnd
EndFunc

为什么这样不能让 Listbox 选择第一条
发表于 2014-1-16 17:21:10 | 显示全部楼层
本帖最后由 kevinch 于 2014-1-16 17:23 编辑

细看了一下,确实没有获取数量的,不过数据都是你写入的,这个是可以用变量记录数量的
设置选择的倒是有,你肯定没注意到:
ControlCommand("","",$List1,"SetCurrentSelection",0)  ;通过指定出现次序(从0开始,0 代表第一个)把 ListBox 或 ComboBox 的当前选择项设为指定的项目
ControlCommand("","",$List1,"SelectString", '字符串')  ;通过指定字符串把 ListBox 或 ComboBox 的当前选择项设为匹配字符串的项目
发表于 2014-1-25 15:52:59 | 显示全部楼层
本帖最后由 netegg 于 2014-1-25 15:55 编辑

#include <GuiListBox.au3>
_GUICtrlListBox_GetCount
获取数量
_GUICtrlListBox_SetCurSel($hWnd, $iIndex)
设置该索引项目为当前选定项
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 10:38 , Processed in 0.079485 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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