当前位置:编程学习 > VB >>

vb 2010 中的 combobox怎样用

求以下的vb 2010 code : 有个 combobox, 专门是用来让用家选择日期的. combobox1的选项分别有d1,d2,d3 按下command Button之后,如果用家选中了其中一个日期, 我要把那个日期存起为 n1 (n1我会用在module里面,几张form都要用到),但如果没有被选中日期,我要弹一个msgbox("You must select a date for departure.",vbOKonly) . 请问这段code怎样打? module我会用的,只是不清楚combobox的code的格式是什么样的. 不是很清楚 additem , clear 那些到底怎样用... 我知道如果用checkbox, 那段code就会是: If checkbox1.checked = true Then checkbox1.text = n1 Else msgbox ("You must select a date for departure.") End if 但问题是现在要用combobox 求教了 各位大侠 不需要很复杂的,做到这个要求就行了,谢谢!
追问:什么叫数组传递?
string? integer? 那些吗?
答案:
vb6.0的Combo1 与 vb2010的Combobox1用法有很大区别,就你补充的代码可以这样实现:
Me.ComboBox1.Items.Clear()
        Dim arrayindex As Integer = 0
        Dim m0 As Integer = 5 '姑且等于5吧
        For j As Integer = 1 To m0
            arrayindex = arrayindex + 1
            Me.ComboBox1.Items.Add(gg(j)) 'gg() 要你事先求好
            Microsoft.VisualBasic.Compatibility.VB6.SetItemData(ComboBox1, ComboBox1.Items.Count() - 1, arrayindex) '要引用Microsoft.VisualBasic.Compatibility
        Next j
        ComboBox1.Text = ComboBox1.Items(i - 1) ' i你要事先定义付值
其他:你combobox是用数组传递的吗、 

上一个:vb中 提醒text中输入必须为正整数的 代码怎么编写呀
下一个:VB小问题,在线等~~~10秒钟就能解决,跪求解释

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,