accessing control collection in tabcontrol

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have an tab control in one of the forms and it has two tab strips. Now I
have written an general function that accepts form name as parameter and
iterates through all the controls in the form and re-initialises that.
Now in this context, i have around 15 controls on one of the tab strips page
1 and 5 controls in tab strip 2.
now when i iterate through the controls, i am getting the control collection
as 3 as there are two more button on the page.
Can anyone please help me how do i access all the controls on the tabstrip.
Here is the code that i am using for the same.

Public Sub ClearFormElements(ByVal sForm As Form)
Dim vControl As System.Windows.Forms.Control

For Each vControl In sForm.Controls
If TypeOf vControl Is System.Windows.Forms.TextBox Then
vControl.Text = ""
End If

If TypeOf vControl Is System.Windows.Forms.ComboBox Then
vControl.Text = ""
End If

If TypeOf vControl Is System.Windows.Forms.DateTimePicker Then
vControl.Text = Convert.ToDateTime(Now()).ToString
End If

If TypeOf vControl Is
System.Windows.Forms.TabControl.ControlCollection Then

End If
Next
End Sub

Regards
Sudhakara.T.P.
 
Sudhakara,

I did not completly try this routine, however I think that it fullfils your
needs.

\\\
doset(MyTabControl)
///
\\\
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
ctr.Text = Nothing
doSet(ctr)
Next
///
This should set every control in your tabcontrol to its initial state.
(Assuming that you did not set something using the designer)

Every control inherits from control from which text is a property.

I hope this helps,

Cor

End Sub
 
Hi Cor Lighert,

Bravo !!!! That worked like a Bullseye. Thanks for the information.

Thanks & Regards
Sudhakara.T.P.
 
Hi,
In continuation with our discussion, with this generic function, as we clear
the text box like vControl.text="", how can we uncheck a check box. Because
when I say this vControl.checked=false, it gives an error. Any idea about
this. If possible, can you let me know where I can find these type of
information.

Regards
Sudhakara.T.P.
 
Sukhakara,

In this case does the text set the text from that box. The checkstate is

if typeof ctr Is checkbox then
ctr.CheckState = CheckState.Unchecked
End if

I hope this helps,

Cor
 
Hi Cor,
As I have declared ctr as system.windows.forms.control, the moment I type
ctr.checkState, it gives an compile error saying that checkstate is not a
member of system.windows.forms.control. Any updates on this.

I had tried this earlier, but had the same problem.

Regards
Sudhakara.T.P.
 
Sukhakara,

Sometimes I type things direct in the message and see than that I do crazy
things, I do it now again however assume it is now right.

Text is a property from Control, however checkstate not that is added with
the created checkbox which inherits from control. And therefore should be
told that it is a checkbox

\\\
if typeof ctr Is checkbox then
directcast(ctr,checkbox).CheckState = CheckState.Unchecked
End if
///

I hope that this goes better.

Cor
 
Hi Cor,

Thanks. That worked the way it should have.

Thanks once again and that is the reason why I always rely on this site.

Thanks
Sudhakara.T.P.
 
Back
Top