GroupBox中每个控件的数据源

时间:2013-01-30 08:38:13

标签: vb.net winforms controls

这是可能的事情。我正在粘贴代码并且跳跃任何人都可以告诉我正确的方法。

 For Each tbbox As TableLayoutPanel In GroupBox3.Controls
'looping through all controls in my tablelayoutpanle
            For Each ctl As Control In tbbox.Controls
                If ctl.Name.StartsWith("cb_barva") Then
'im stuck here...
                    With (ctl)
                        .DataSource = ds_barve.Tables("moje_barve")
                        .DisplayMember = "barva"
                        .ValueMember = "barva"
                        .SelectedIndex = 0
                    End With

                End If
            Next
        Next

1 个答案:

答案 0 :(得分:1)

您需要进行类型转换

With (ctl)

将ctl转换为ComboBox

ctype(ctl,ComboBox)

如果您无法使用“With”语句转换控件,则更改代码的每一行,如下所示....

        ctype(ctl,ComboBox).DataSource = ds_barve.Tables("moje_barve")
        ctype(ctl,ComboBox).DisplayMember = "barva"
        ctype(ctl,ComboBox).ValueMember = "barva"
        ctype(ctl,ComboBox).SelectedIndex = 0