English 中文(简体)
检查下拉下降值
原标题:Check value in dropdown

我要检查下拉列表中的值。 列表被预先配置为持有是或否 。

现在,我正在使用一个复选框, 看起来像这个:

If chkboxOne.Value = vbChecked And (LenB(txtDetailsRefNo.Text) = 0) Then
    If vblnShowErrors Then Err.Raise 10000, VALIDATION, "A Default Reference Number must be entered."
    blnDataFail = True
  End If  

我可以简单地将 Chkboxone 更改为“ cboboxone ”, 用复选框换成窗体上的复选框, 用 True 替换“ vbcecked ” 吗? 我不知道他们的功能有多相似, 语法是明智的 。

谢谢 谢谢

最佳回答

要在组合框中获取此项目, 您可以检查 < code> list index 来查看所选项目( 没有 < code> value 属性) 。

cboboxOne.AddItem "yes"     //listindex is 0
cboboxOne.AddItem "no"      //listindex is 1
cboboxOne.AddItem "maybe"   //listindex is 2

...
if (cboboxOne.ListIndex = 0) Then  // yes selected

您也可以检查选中的文字 :

if (cboboxOne.List(cboboxOne.ListIndex) = "yes") Then  // yes selected

您也可以使用 ItemData 测试自定义整数

cboboxOne.AddItem "yes"
cboboxOne.ItemData(cboboxOne.NewIndex) = 42
cboboxOne.AddItem "no" 
cboboxOne.ItemData(cboboxOne.NewIndex) = &HBEEF

...
if (cboboxOne.ItemData(cboboxOne.ListIndex) = 42) Then  // yes selected
问题回答

暂无回答




相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签