【问题标题】:Is it possible to use Findcomponet method in vb.net?是否可以在 vb.net 中使用 Findcomponet 方法?
【发布时间】:2014-11-20 02:31:08
【问题描述】:

表单上有七个组合框

我想在每个组合框中添加项目。但我不想手动模式来添加项目。

我想使用 ForLoop 来添加项目。

我尝试这样,但第二行是发生异常。

将 cmb_Temp 调暗为 ComboBox = 新 ComboBox cmb_Temp.Name = "cmb_a" + "7"

所以,我不知道如何处理 ForLoop 以添加项目。

在 vb.net 中是不可能的吗?

是否使用 FindeComponet 方法?

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    假设 WinForms,您可以像这样使用 Controls.Find():

        Dim matches() As Control
        For i As Integer = 1 To 7
            matches = Me.Controls.Find("cmb_a" & i, True)
            If matches.Length > 0 AndAlso TypeOf matches(0) Is ComboBox Then
                Dim cb As ComboBox = DirectCast(matches(0), ComboBox)
                cb.Items.Add("SomeItem")
            End If
        Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多