PC Review


Reply
Thread Tools Rate Thread

accessing control collection in tabcontrol

 
 
=?Utf-8?B?U3VkaGFrYXJhLlQuUC4=?=
Guest
Posts: n/a
 
      8th Aug 2005
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.
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      8th Aug 2005
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


 
Reply With Quote
 
=?Utf-8?B?U3VkaGFrYXJhLlQuUC4=?=
Guest
Posts: n/a
 
      8th Aug 2005
Hi Cor Lighert,

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

Thanks & Regards
Sudhakara.T.P.

"Cor Ligthert [MVP]" wrote:

> 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
>
>
>

 
Reply With Quote
 
=?Utf-8?B?U3VkaGFrYXJhLlQuUC4=?=
Guest
Posts: n/a
 
      11th Aug 2005
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.
> "Cor Ligthert [MVP]" wrote:
>
> > 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
> >
> >
> >

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      11th Aug 2005
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



 
Reply With Quote
 
=?Utf-8?B?U3VkaGFrYXJhLlQuUC4=?=
Guest
Posts: n/a
 
      20th Aug 2005
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.

"Cor Ligthert [MVP]" wrote:

> 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
>
>
>
>

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      20th Aug 2005
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


 
Reply With Quote
 
=?Utf-8?B?U3VkaGFrYXJhLlQuUC4=?=
Guest
Posts: n/a
 
      20th Aug 2005
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.

"Cor Ligthert [MVP]" wrote:

> 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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
Accessing scrollbar in a TabControl aabdelwahab@comcast.net Microsoft C# .NET 2 13th Oct 2006 03:04 PM
Can't get collection to save when using collection of custom class as property of control in VS 2005 J.Edwards Microsoft Dot NET Compact Framework 0 10th Jan 2006 04:44 AM
Accessing all controls on a tabcontrol?? Paul Bromley Microsoft VB .NET 2 21st Oct 2005 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 PM.