在表单上循环组合框并清除数据源

时间:2018-01-21 17:27:35

标签: combobox datasource

我在表单上循环组合框并清除数据源时遇到了一些问题(在Visual Studio 2017中使用VB.net)

到目前为止,我的代码是:

==============================

    For Each c As Control In Me.Controls.OfType(Of ComboBox)()
        If c.Name IsNot Control.Name Then c.datasource = Nothing
    Next

==============================

然而,得到错误" '数据源'不是'控制'的成员。 "

" Control"是传递给子

的变量

====================

Public Sub Item_Select(ByRef Field As String, ByRef Control As Control)

====================

并且像这样调用

==================

Dim Control1 As Control = ComboBox2
Item_Select("Last_Name", Control1)

==================

数据源是一个SQL表

有人能指出我正确的方向吗?我似乎没有在谷歌中获得正确的搜索条件,以获得可行的解决方案!

非常感谢,如果这篇文章不合适,我会道歉(我已经阅读了指南!)

1 个答案:

答案 0 :(得分:0)

这是一个解决方案!

For Each c As Control In Me.Controls
              If TypeOf c Is ComboBox Then
                  Dim ctrl = DirectCast(c, ComboBox)
                  ctrl.DataSource = Nothing
              End If
Next
相关问题