Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:18:12+00:00 2026-05-27T10:18:12+00:00

in VB.NET i have 2 custom controls, one is a TextBox and second one

  • 0

in VB.NET i have 2 custom controls, one is a TextBox and second one is a ComboBox.
These have custom values like Bool _IsHidden and are added on runtime to a form.

Now, at some point in the code I want to check if the _IsHidden is set to True or False and display that information. Since the user can edit this values when creating the control these are not set on creation.

So what I tried is:

(all of this is on MDI Forms)

For Each frm as CustomForm in Main.MdiChildren
If frm.MyName = calledBy Then 'this part is just to know which form called the form to create the object
For Each cntrl as CustomTextBox in frm.Controls
'DO Something
Next
End if
Next

Now.. if the first control is a custom ComboBox it thorws an error since it sees that it does not match the custom TextBox control..

how do i get around this? By my understanding it should just go through all of the controls on the said form and just check those who match CustomTextBox control ?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:18:12+00:00Added an answer on May 27, 2026 at 10:18 am

    For Each x As T In collection does not filter your collection items to those of type T. It tries to convert every item in collection to T and throws an exception if that fails.

    Thus, you have the following options:

    1. Do the check yourself, for example, using the code provided by RB.

    2. Alternatively, you could filter your list first, and then loop through the items. Here, LINQ can help:

      For Each cntrl In frm.Controls.OfType(Of CustomTextBox)()
          ... ' Do this for all CustomTextBoxes
      Next
      
      For Each cntrl In frm.Controls.OfType(Of CustomComboBox)()
          ... ' Do this for all CustomComboBoxes
      Next
      

      You don’t need the As CustomTextBox clause here, since frm.Controls.OfType(Of CustomTextBox)() returns an IEnumerable(Of CustomTextBox), so For Each can infer by itself that cntrl must be of type CustomTextBox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create custom Textbox control in asp.net.But i have one doubt when
I would like to know if somebody knows free custom nice controls for .NET
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I have created a simple Asp.Net custom control which automatically combines all the correct
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have a custom memebership provider that has served us well for asp.net web
So i have a custom CMS running under .Net 3.5 written entirely in c#.
I use declarative roles in my MVC.NET controllers and I have a custom membership
I'm using Microsoft Sync framework 1.0 (without ADO.NET services) I have created 2 custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.