[英]Datasource for every control in GroupBox
有什么可能的。 我正在粘貼下面的代碼,希望任何人都可以向我展示正確的方法。
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
您需要類型轉換
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.