• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

How do I count the number of textboxes in the selected tab?

Hello

I have some code that programatically adds a textbox to a selected tab. I need to add a handler that sees if there are already 10 textboxes on the tab. If there are then it bails out. Any suggestions how I do this?

I am unsing VB.Net in VS Studio 2003

Thanks

PB
0
PBLack
Asked:
PBLack
  • 2
1 Solution
 
iHadiCommented:
Hi PBLack

Add a tab control on your form with some textboxes on it and try the following code:

        Dim tmpPanel As Panel
        Dim Ctrl As Control
        Dim iType As Type
        Dim I As Integer
        tmpPanel = CType(TabControl1.SelectedTab, Panel)
        For Each Ctrl In tmpPanel.Controls
            iType = Ctrl.GetType
            If iType.Equals(GetType(System.Windows.Forms.TextBox)) Then
                I = I + 1
            End If
        Next
        Label1.Text = I.ToString
0
 
iHadiCommented:
Hi PBLack

Add a label and a tab control  on your form with some textboxes on it and try the following code:

        Dim tmpPanel As Panel
        Dim Ctrl As Control
        Dim iType As Type
        Dim I As Integer
        tmpPanel = CType(TabControl1.SelectedTab, Panel)
        For Each Ctrl In tmpPanel.Controls
            iType = Ctrl.GetType
            If iType.Equals(GetType(System.Windows.Forms.TextBox)) Then
                I = I + 1
            End If
        Next
        Label1.Text = I.ToString
0
 
Fernando SotoRetiredCommented:
Hi PBLack;

Set a form level variable to keep count of the number of TextBoxes on the Panel, something like this:
   
    Private Panel1TBCount As Integer = 0

When you add a TextBox to the Panel add 1 to Panel1TBCount.
When you remove a TextBox from the Panel subtract 1 from Panel1TBCount.

Then to check if the Panel has 10 TextBoxes or not just test the variable Panel1TBCount.

    If Panel1TBCount >= 10 then
        Return
    End If

Fernando
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now