|
-
May 27th, 2011, 02:01 PM
#1
Thread Starter
Fanatic Member
Restting all Checked "type" controls in containers.
I know how to do it individually but not sure if it's possible to merge into one.
I have 6 containers that contain either Checkbox or RadioButtons.
Struggling sending the type of control and also wondered do i really need to call clear 6 times? Can't VB search each container for a control that can be checked?
vb Code:
#Region "Form Events"
Private Sub ClearPizzaCreation(Of t As Control)(ByVal root As Control)
For Each ctrl As Control In root.Controls
If TypeOf ctrl Is CheckBox OrElse TypeOf ctrl Is RadioButton Then
DirectCast(ctrl, t).Checked = False
End If
Next ctrl
End Sub
#End Region
Private Sub btnStartAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
btnStartAgain.Click
ClearPizzaCreation(Of CheckBox)(flpnlToppings)
ClearPizzaCreation(flpnlSize)
ClearPizzaCreation(flpnlBase)
ClearPizzaCreation(flpnlDrink)
End Sub
-
May 27th, 2011, 02:08 PM
#2
Re: Restting all Checked "type" controls in containers.
are the container controls all panels?
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each p As Panel In Me.Controls.OfType(Of Panel)()
For Each cb As CheckBox In p.Controls.OfType(Of CheckBox)()
cb.Checked = False
Next
For Each rb As RadioButton In p.Controls.OfType(Of RadioButton)()
rb.Checked = False
Next
Next
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 27th, 2011, 02:12 PM
#3
Thread Starter
Fanatic Member
Re: Restting all Checked "type" controls in containers.
Hi paul they are all flow panels if that helps. Instea dof looping twice inside the loop can it not be sent. The control type i mean?
-
May 27th, 2011, 02:15 PM
#4
Re: Restting all Checked "type" controls in containers.
this should work:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each flp As FlowLayoutPanel In Me.Controls.OfType(Of FlowLayoutPanel)()
For Each cb As CheckBox In flp.Controls.OfType(Of CheckBox)()
cb.Checked = False
Next
For Each rb As RadioButton In flp.Controls.OfType(Of RadioButton)()
rb.Checked = False
Next
Next
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 27th, 2011, 02:17 PM
#5
Re: Restting all Checked "type" controls in containers.
You will have to loop somewhere.
There is a theoretical alternative where you use reflection to figure out whether or not there is a .Checked property of the given object, but there is no sound reason to do this. Even without testing, I feel pretty certain that such a loop would perform much worse than the code .Paul. posted.
My usual boring signature: Nothing
 
-
May 27th, 2011, 02:25 PM
#6
Thread Starter
Fanatic Member
Re: Restting all Checked "type" controls in containers.
Works a charm.
SH i understand completly what you are saying. But i was more getting at i know which flow panel contrains either a check or a radio control. So when i am calling the sub i can send for example
CallMySub(FlowPanelName, Checkbox)
or
CallMySub(FlowPanelName, Radiobutton)
-
May 27th, 2011, 03:15 PM
#7
Re: Restting all Checked "type" controls in containers.
Depending on what you are doing, it may not matter whether you pass in a checkbox or a radiobutton. Those two controls are so similar that for most situations, passing in a Control would work as long as it was one of those two types. That may not make anything easier, since it would just be a matter of an OR that wouldn't be so good, but there are cases where it would be useful.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|