找回密码
 加入
搜索
查看: 2429|回复: 10

删除Combo控件条目

[复制链接]
发表于 2008-12-3 14:00:12 | 显示全部楼层 |阅读模式
#include <GUIConstants.au3>

GUICreate("GUI")
$Combo = GUICtrlCreateCombo ("条目1", 10,10, -1,-1,0x0003)
GUICtrlSetData(-1,"条目2|条目3","条目3")
GUICtrlCreateButton("删除",222,10,50,22)
GUISetState ()

While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


如上,要删除当前选中的条目,AU3貌似没有现成的函数。
现在自己的做法,是先把条目清空,再重新建立:

GUICtrlSetData($Combo,"")
GUICtrlSetData($Combo,"条目1|条目2","条目1")


以上仅为说明问题的演示,实际还得判断删除的是哪一条,并记录删除次数以防删空。
实际运用时可能更繁复。
本来应该是一个命令直接删除,结果得绕这么大圈,所以总觉得这种方法稍显弱智。
AU3自带UDF:_GUICtrlComboBox_BeginUpdate似乎有类似功能,
但看了一下,如果用来实现上面的功能,比自己的方法还要烦琐...
所以,想请问各位达人有什么高招,恳请指点,谢谢。

PS:目前所用的版本是3.2.10.0

[ 本帖最后由 McAu 于 2008-12-10 22:22 编辑 ]
发表于 2008-12-3 14:35:51 | 显示全部楼层
这要看你的combo中的条目和你的操作了,如果少而且项目确定,就用第一种
发表于 2008-12-3 14:37:55 | 显示全部楼层
_GUICtrlComboBox_BeginUpdate,这个函数是不管删除的,只是为了实时显示
 楼主| 发表于 2008-12-3 16:09:43 | 显示全部楼层
问题的根本其实就是动态显示增删后条目的变化。
条目是不确定的,是读取一些数据后动态生成的,
用清空重建,就得再次读取,再次生成。
总之删除几条,就得重建几次,总觉得貌似走了弯路。
所以想知道各位达人有没有更好的思路。
发表于 2008-12-3 16:38:17 | 显示全部楼层
的确是可以直接的改变!
For Combo or List control :
If the "data" corresponds to an already existing entry it is set as the default.
If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed.
发表于 2008-12-4 06:07:47 | 显示全部楼层
把控件的表达部分放到一个自定义函数中调用

另外,如果没理解错,你的意思是不是,删了当时就看见删了,没有过程?

[ 本帖最后由 netegg 于 2008-12-4 06:11 编辑 ]
发表于 2008-12-4 12:29:30 | 显示全部楼层
If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed.
给个代码例子:

GUICtrlSetData($Combo,"")
GUICtrlSetData($Combo,"|条目1|条目2","条目1")
发表于 2008-12-4 20:40:02 | 显示全部楼层
先用_arrayadd()读取所有条目,
然后将选中的条目从数组中删除,
then 将数组加载到combo中,这样可不可以?
发表于 2008-12-8 17:16:59 | 显示全部楼层
#include <GUIConstants.au3>
#Include <GuiComboBox.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 527, 397, 193, 125)
$Combo1=GUICtrlCreateCombo("", 136, 176, 273, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1,"test|test1|test2|test3|test4","test")
$Button1 = GUICtrlCreateButton("delete", 88, 288, 81, 41, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                        case $Button1
                                                ;$CurSel=_GUICtrlComboBox_GetCurSel($Combo1)
                        _GUICtrlComboBox_DeleteString($Combo1,_GUICtrlComboBox_GetCurSel($Combo1))
                                                _GUICtrlComboBox_SetCurSel($Combo1,_GUICtrlComboBox_GetCurSel($Combo1)+1)
                                
        EndSwitch
WEnd
发表于 2008-12-8 21:36:07 | 显示全部楼层
_GUICtrlComboBox_DeleteString($Combo1, _GUICtrlComboBox_GetCurSel($Combo1))
 楼主| 发表于 2008-12-10 22:21:55 | 显示全部楼层
看来还得加强UDF的学习.. 多谢9楼
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 15:59 , Processed in 0.074820 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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