怎样在VB的combox里添加选项

怎样在VB的combox里添加选项,第1张

为Combox添加选项有几个方法

1、窗体设计时

属性窗口中找到List属性,直接添加即可,如下图:

2、通过代码添加

Combo1.AddItem "内容"

dim j

for j=0 to combox.listcount-1

if combo1.list(i)=你要对比的字符串 then

msgbox("存在相同项目")

end if

next j

就是用list属性,后面的括号是数字,就是combo控件中的项目号,

明白这个属性了,你就知道咋做了。

首先定义一个公共的方法

public void BindComBox(ComboBox comBox,DataSet ds)

{

comBox.DataSource=ds.Tables[0].DefaultView

comBox.DisplayMember = "Type"

comBox.ValueMember = "Type"

}

然后在页面上调用

Page_Load()

{

Maticsoft.BLL.T_Banci banci = new Maticsoft.BLL.T_Banci()

DataSet ds = banci.GetList("")

BindComBox(comBox1,ds)

BindComBox(comBox2,ds)

BindComBox(comBox3,ds)

BindComBox(comBox4,ds)

BindComBox(comBox5,ds)

BindComBox(comBox6,ds)..................................

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11734649.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存