我明白你的意思,我在寫數據庫時也碰到過這個問題。 當style=dropdownlist時,讀數據庫中的內容到combox中時候,如果用text屬性會出現問題,因為此時,text屬性是只讀的,但我們可以用它的索引值來改變TEXT。 public function getindex(byval strval as string,byval cbo as combobox) as integer for i=0 to cbo.listcount-1 if trim(cbo.list(i))=trim(strval) then getindex=i goto exitsub end if next getindex=-1 exitsub: exit function end function 然後這樣引用: combobox1.listindex=getindex(strval,combobox1)
Combo1.additem "second"
Combo1.additem "third"如果要选中第二项,有两种办法:
first:
Combo1.Text= "second"
second:
Combo1.ListIndex=1
'ComDlLx4.ItemData(ComSsL3.NewIndex) = 0
'ComDlLx4.ListIndex = ComDlLx4.ListCount - 1
我前两天没说太清楚,我要做到的是这样一个效果,
我在additem语句中无法指定后面的数字,
我需要在程序中指定它要显示的内容,也就是说我需要执行象Combo1.Text= "second"这样的命令,所以style只能设置成0-dropdown
第三点,style设置成0-dropdown的时候用户可以修改里面显示的内容,而我又不希望如此
怎么办?
这样它不就不能改了吗?
當style=dropdownlist時,讀數據庫中的內容到combox中時候,如果用text屬性會出現問題,因為此時,text屬性是只讀的,但我們可以用它的索引值來改變TEXT。
public function getindex(byval strval as string,byval cbo as combobox) as integer
for i=0 to cbo.listcount-1
if trim(cbo.list(i))=trim(strval) then
getindex=i
goto exitsub
end if
next
getindex=-1
exitsub:
exit function
end function
然後這樣引用:
combobox1.listindex=getindex(strval,combobox1)