1

这有可能吗。我在下面粘贴代码,希望任何人都可以向我展示正确的方法。

 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
4

1 回答 1

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
于 2013-01-30T09:19:38.747 回答