vb.net combobox selectedvalue事件错误

时间:2013-07-26 18:09:08

标签: vb.net combobox

我收到此错误“运营商'='未定义类型'CivilStatus'并输入'整数'。”

代码:

Private Sub cboCivilStatus_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCivilStatus.SelectedValueChanged

    If cboCivilStatus.SelectedValue = 2 Then
        dtpDateMarried.Enabled = True
    Else
        dtpDateMarried.Enabled = False
    End If

End Sub

2 个答案:

答案 0 :(得分:2)

好的,你应该尝试使用Combobox SelectedIndexChanged事件

Private Sub cboCivilStatus_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCivilStatus.SelectedIndexChanged
        If cboCivilStatus.Text = "2" Then
            dtpDateMarried.Enabled = True
        Else
            dtpDateMarried.Enabled = False
        End If

    End Sub

答案 1 :(得分:0)

看起来SelectedValue包含类CivilStatus的对象。如果您要查找所选项目的索引,请改为使用cboCivilStatus.SelectedIndex属性:

If cboCivilStatus.SelectedIndex = 2 Then

但是如果您需要CivilStatus的属性,则需要检查该属性,例如

If CType(cboCivilStatus.SelectedValue, CivilStatus).MyIntProperty = 2 Then