[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help getting all text box names from all tab pages on a tab

Posted on 2007-07-23
6
Medium Priority
?
170 Views
Last Modified: 2013-11-07
Using VB.Net 2005, Compact Framework 2.0

I am trying to loop through all controls in a each tab page from a tab called 'tabProj' and get the name of any controls  that are a textbox. I only need them to show in a  msgBox. How would I do that?

Here is what I have thus far and don't know how to fix it:

Tried this:

        Dim tabPag As TabPage
        Dim txtBox As TextBox
        For Each tabPag In tabProj.TabPages
            For Each ctrl As Control In tabPag.Controls
                If ctrl typeof txtBox Then
                    MsgBox(txtBox.Name)
                End If
            Next
        Next

Then This:

        Dim tabPag As TabPage
        Dim txtBox As TextBox
        For Each tabPag In tabProj.TabPages
            For Each ctrl As Control In tabPag.Controls
                If ctrl.GetType = txtBox Then
                    MsgBox(txtBox.Name)
                End If
            Next
        Next
0
Comment
Question by:PBLack
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19549388
Try this

this C# code convert to vb

foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control ctr in page.Controls)
                {
                    TextBox txt = (TextBox) ctr;
                    MessageBox.Show(txt.Text);
                }
            }
0
 

Author Comment

by:PBLack
ID: 19549453
I converted as follows:

        For Each page As TabPage In tabProj.TabPages
            For Each ctr As Control In page.Controls
                Dim txt As TextBox = DirectCast(ctr, TextBox) 'error thrown here
                MessageBox.Show(txt.Name)
            Next
        Next

Error thrown:
System.InvalidCastException was unhandled
  Message="InvalidCastException"

When casting from a number that number must be less than infinity
 
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 19549501
Try this

        Dim tabpag As TabPage
        For Each tabpag In tabProj.TabPages
            For Each ctrl As Control In tabpag.Controls
                Dim result As Boolean = TypeOf ctrl Is TextBox
                If result Then
                    MsgBox(ctrl.Name)
                End If
            Next
        Next
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:sabeesh
ID: 19549557
This is because you are trying to cast some other control other  than text box
 so put a try catch

 foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control ctr in page.Controls)
                {
                    try
                    {
                        TextBox txt = (TextBox)ctr;
                        MessageBox.Show(txt.Text);
                    }
                    catch
                    { }
                }
            }
0
 
LVL 8

Expert Comment

by:sabeesh
ID: 19549586
jpaulino is right try that one only
0
 

Author Comment

by:PBLack
ID: 19549699
Thanks
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question