vb.net组合框selectedvalue事件错误
我有一个错误“运算符“=”没有为“CivilStatus”类型和“Integer”类型定义。” 代码:vb.net组合框selectedvalue事件错误,vb.net,combobox,Vb.net,Combobox,我有一个错误“运算符“=”没有为“CivilStatus”类型和“Integer”类型定义。” 代码: 好的,您应该尝试使用组合框SelectedIndexChanged事件 Private Sub cboCivilStatus_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCivilStatus.SelectedIndexChanged If cboCivilStatus.Text = "2"
好的,您应该尝试使用组合框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
它看起来像是
SelectedValue
包含一个类为CivilStatus
的对象。如果要查找所选项目的索引,请使用cboCivilStatus.SelectedIndex
属性:
If cboCivilStatus.SelectedIndex = 2 Then
但是,如果您需要CivilStatus
属性,则需要对照该属性进行检查,例如
If CType(cboCivilStatus.SelectedValue, CivilStatus).MyIntProperty = 2 Then
我得到这个错误“无法将'System.int64'类型的对象强制转换为'ChurchData.CivilStatus'”只是为了澄清-您需要检查下拉列表中的第二个元素还是特定属性为2的元素?我只是想在组合框的选定值为2时启用日期时间选择器控件。组合框绑定到civilstatus类。在数据库CivilStatus='marred',ID=2中。您可以将断点放在IF语句处,将
cboCivilStatus.SelectedValue
添加到手表中,查看它等于什么以及它具有什么属性?手表1:Name:cboCivilStatus.SelectedValue Long,Value:2{Long}2,类型:对象长度我尝试了所选的文本,但未启用DTPDATE控件。我应该把代码放在什么事件上?
If CType(cboCivilStatus.SelectedValue, CivilStatus).MyIntProperty = 2 Then