最佳解答者
判斷GroupBox內的控制項選取

問題
解答
-
Hi,小歐的程式已經點出了16個都沒選或是16個中有被點選的狀態您只要以此類推變通一下就好吧像這樣
Dim chkFlag = False For Each ctl As Control In Me.GroupBox1.Controls If TypeOf (ctl) Is CheckBox Then Dim rb As CheckBox = CType(ctl, CheckBox) If rb.Checked Then chkFlag = True End If End If Next If not chkFlag Then MessageBox.Show("請選擇測試頻道", "訊息") Return End If ...DoSomeThing...
大家提供給您的提示並不一定會完全照你需求開的做要自己體會
謙卑學習,持之以恆,才能不斷的Level Up http://www.dotblogs.com.tw/larrynung/- 已標示為解答 circle3 2010年1月15日 上午 09:04
所有回覆
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim chkFlag = False For Each ctl As Control In Me.GroupBox1.Controls If TypeOf (ctl) Is CheckBox Then Dim rb As CheckBox = CType(ctl, CheckBox) If rb.Checked = True Then chkFlag = True Exit For End If End If Next If chkFlag = False Then ' 如果16個都沒選取,就顯示提醒勾選訊息然後exit sub MessageBox.Show("請選擇測試頻道", "測試") Exit Sub End If '如果其中一個有選(甚至多選),就通過判定繼續執行下面動作 MessageBox.Show("你要做的事情") End Sub
- 已提議為解答 Larry Nung(蹂躪)MVP 2010年1月14日 上午 10:11
- 已編輯 小歐ouMVP, Moderator 2010年1月14日 上午 10:19
-
hi
嘗試看看
Dim checked As Boolean = False
For Each MyControl As Control In Me.GroupBox1.Controls
If TypeOf MyControl Is CheckBox And CType(MyControl, CheckBox).Checked Then
checked = True
Exit For
End If
Next
If (checked <> True) Then
MessageBox.Show("請選擇測試頻道", "訊息")
End If
http://www.dotblogs.com.tw/ricochen/Default.aspx- 已提議為解答 Larry Nung(蹂躪)MVP 2010年1月14日 上午 10:11
-
Hi,小歐的程式已經點出了16個都沒選或是16個中有被點選的狀態您只要以此類推變通一下就好吧像這樣
Dim chkFlag = False For Each ctl As Control In Me.GroupBox1.Controls If TypeOf (ctl) Is CheckBox Then Dim rb As CheckBox = CType(ctl, CheckBox) If rb.Checked Then chkFlag = True End If End If Next If not chkFlag Then MessageBox.Show("請選擇測試頻道", "訊息") Return End If ...DoSomeThing...
大家提供給您的提示並不一定會完全照你需求開的做要自己體會
謙卑學習,持之以恆,才能不斷的Level Up http://www.dotblogs.com.tw/larrynung/- 已標示為解答 circle3 2010年1月15日 上午 09:04