【发布时间】:2017-09-18 11:23:20
【问题描述】:
我开发了一个 vb.net 应用程序,但我遇到了组合框问题。
我知道我的组合框上的选定项目何时更改:
Private Sub ComboBoxSite_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxSite.SelectedIndexChanged
If (ComboBoxSite.SelectedIndex <> 0) Then 'If it is not the default value
Console.WriteLine("ActionListenerIndex = {0}", ComboBoxSite.SelectedIndex) 'To debug
RequestAccesv2(0)
End If
End Sub
还有 RequestAccessv2() 函数
Private Sub RequestAccesv2(taille As Integer)
initBoxesLocation() 'A function that clear/refill 4 comboBoxes
Console.WriteLine("SELECTED INDEX SITE : {0}", ComboBoxSite.SelectedIndex)
Select Case taille
Case 0 ..... 'Some database treatment
End Sub
输出上有结果,当调用第二个函数时,我没有相同的 selectedIndex :
ActionListenerIndex = 2
SELECTED INDEX SITE : -1 'Does it means thas nothing is selected ?
您是否已经/解决了这个问题?
问候, 法比恩
【问题讨论】:
-
initBoxesLocation 的代码是什么?您似乎以某种方式更改了该函数中的 SelectedIndex 。请edit您的问题添加该代码
-
如果您“清除/重新填充组合框”,则所选项目将被删除,
SelectedIndex重置回-1 -
实际上第一项在索引 0 处。所以当您从第二个索引更改为第一个索引时,
If (ComboBoxSite.SelectedIndex <> 0) Then不会通过。这是故意的吗?
标签: vb.net combobox selecteditem selectedindex