[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Empty textboxes on a form

Posted on 2016-08-24
6
Medium Priority
?
49 Views
Last Modified: 2016-08-24
Hello,

Is there any ways I can  code to get all empty textboxes on a windows form.

Cheers
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Accepted Solution

by:
Jeff Darling earned 2000 total points
ID: 41768692
something like this

For Each tb As TextBox In Me.Controls.OfType(Of TextBox)()
  if tb.Text = "" then
   ' do something
  end if
Next

Open in new window

0
 
LVL 15

Expert Comment

by:Lokesh B R
ID: 41768697
Hi,

You can clear as follows.

1. Write a function as below.

void ClearAllControls(Control con)
{
    foreach (Control c in con.Controls)
    {
      if (c is TextBox)
         ((TextBox)c).Clear();
      else
         ClearAllControls(c);
    }
}

Open in new window


2. Call the function as below on button click

ClearAllControls(this);
0
 

Author Comment

by:RIAS
ID: 41768702
Thanks ,don't want to clear but ,want to find empty textboxes
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Closing Comment

by:RIAS
ID: 41768703
Cheers!
0
 
LVL 34

Expert Comment

by:it_saige
ID: 41769030
I should point out that while the proposed solution does enumerate textbox controls that are directly on the form, it does not enumerate textbox controls that are on child container controls that are on the form.  You must also check to see if the child control has children; e.g. -

Form1.vb -
Public Class Form1
	Private Sub OnLoad(sender As Object, e As EventArgs) Handles MyBase.Load
		For Each child In Controls.GetChildren(GetType(Label))
			child.Text = child.Parent.Name
		Next

		Label6.Text = String.Format("There is {0} Textbox Control on the Form", Controls.OfType(Of TextBox).Count)
		Label7.Text = String.Format("There are {0} Textbox Controls on the Form and in Containers", Controls.GetChildren(GetType(TextBox)).Count)
	End Sub
End Class

Module Extensions
	<System.Runtime.CompilerServices.Extension()> _
	Public Function GetChildren(source As Control.ControlCollection, Optional ByVal filter As Type = Nothing) As IEnumerable(Of Control)
		Dim children = New List(Of Control)
		For Each child As Control In source
			If child.GetType() Is If(filter IsNot Nothing, filter, GetType(Control)) Then children.Add(child)
			If child.HasChildren() Then children.AddRange(child.Controls.GetChildren(filter))
		Next
		Return children
	End Function
End Module

Open in new window

Form1.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
		Me.TextBox1 = New System.Windows.Forms.TextBox()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.Panel1 = New System.Windows.Forms.Panel()
		Me.Panel2 = New System.Windows.Forms.Panel()
		Me.Panel3 = New System.Windows.Forms.Panel()
		Me.Panel4 = New System.Windows.Forms.Panel()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.TextBox5 = New System.Windows.Forms.TextBox()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.TextBox4 = New System.Windows.Forms.TextBox()
		Me.Label3 = New System.Windows.Forms.Label()
		Me.TextBox3 = New System.Windows.Forms.TextBox()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.TextBox2 = New System.Windows.Forms.TextBox()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label7 = New System.Windows.Forms.Label()
		Me.Panel1.SuspendLayout()
		Me.Panel2.SuspendLayout()
		Me.Panel3.SuspendLayout()
		Me.Panel4.SuspendLayout()
		Me.SuspendLayout()
		'
		'TextBox1
		'
		Me.TextBox1.Location = New System.Drawing.Point(301, 10)
		Me.TextBox1.Name = "TextBox1"
		Me.TextBox1.Size = New System.Drawing.Size(100, 20)
		Me.TextBox1.TabIndex = 0
		'
		'Label1
		'
		Me.Label1.AutoSize = True
		Me.Label1.Location = New System.Drawing.Point(13, 13)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(28, 13)
		Me.Label1.TabIndex = 1
		Me.Label1.Text = "Text"
		'
		'Panel1
		'
		Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.Panel1.Controls.Add(Me.Panel2)
		Me.Panel1.Controls.Add(Me.Label2)
		Me.Panel1.Controls.Add(Me.TextBox2)
		Me.Panel1.Location = New System.Drawing.Point(12, 36)
		Me.Panel1.Name = "Panel1"
		Me.Panel1.Size = New System.Drawing.Size(389, 133)
		Me.Panel1.TabIndex = 2
		'
		'Panel2
		'
		Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.Panel2.Controls.Add(Me.Panel3)
		Me.Panel2.Controls.Add(Me.Label3)
		Me.Panel2.Controls.Add(Me.TextBox3)
		Me.Panel2.Location = New System.Drawing.Point(6, 29)
		Me.Panel2.Name = "Panel2"
		Me.Panel2.Size = New System.Drawing.Size(380, 98)
		Me.Panel2.TabIndex = 4
		'
		'Panel3
		'
		Me.Panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.Panel3.Controls.Add(Me.Panel4)
		Me.Panel3.Controls.Add(Me.Label4)
		Me.Panel3.Controls.Add(Me.TextBox4)
		Me.Panel3.Location = New System.Drawing.Point(6, 29)
		Me.Panel3.Name = "Panel3"
		Me.Panel3.Size = New System.Drawing.Size(371, 63)
		Me.Panel3.TabIndex = 5
		'
		'Panel4
		'
		Me.Panel4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.Panel4.Controls.Add(Me.Label5)
		Me.Panel4.Controls.Add(Me.TextBox5)
		Me.Panel4.Location = New System.Drawing.Point(6, 29)
		Me.Panel4.Name = "Panel4"
		Me.Panel4.Size = New System.Drawing.Size(362, 29)
		Me.Panel4.TabIndex = 6
		'
		'Label5
		'
		Me.Label5.AutoSize = True
		Me.Label5.Location = New System.Drawing.Point(3, 6)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(28, 13)
		Me.Label5.TabIndex = 3
		Me.Label5.Text = "Text"
		'
		'TextBox5
		'
		Me.TextBox5.Location = New System.Drawing.Point(259, 3)
		Me.TextBox5.Name = "TextBox5"
		Me.TextBox5.Size = New System.Drawing.Size(100, 20)
		Me.TextBox5.TabIndex = 2
		'
		'Label4
		'
		Me.Label4.AutoSize = True
		Me.Label4.Location = New System.Drawing.Point(3, 6)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(28, 13)
		Me.Label4.TabIndex = 3
		Me.Label4.Text = "Text"
		'
		'TextBox4
		'
		Me.TextBox4.Location = New System.Drawing.Point(268, 3)
		Me.TextBox4.Name = "TextBox4"
		Me.TextBox4.Size = New System.Drawing.Size(100, 20)
		Me.TextBox4.TabIndex = 2
		'
		'Label3
		'
		Me.Label3.AutoSize = True
		Me.Label3.Location = New System.Drawing.Point(3, 6)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(28, 13)
		Me.Label3.TabIndex = 3
		Me.Label3.Text = "Text"
		'
		'TextBox3
		'
		Me.TextBox3.Location = New System.Drawing.Point(277, 3)
		Me.TextBox3.Name = "TextBox3"
		Me.TextBox3.Size = New System.Drawing.Size(100, 20)
		Me.TextBox3.TabIndex = 2
		'
		'Label2
		'
		Me.Label2.AutoSize = True
		Me.Label2.Location = New System.Drawing.Point(3, 6)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(28, 13)
		Me.Label2.TabIndex = 3
		Me.Label2.Text = "Text"
		'
		'TextBox2
		'
		Me.TextBox2.Location = New System.Drawing.Point(286, 3)
		Me.TextBox2.Name = "TextBox2"
		Me.TextBox2.Size = New System.Drawing.Size(100, 20)
		Me.TextBox2.TabIndex = 2
		'
		'Label6
		'
		Me.Label6.AutoSize = True
		Me.Label6.Location = New System.Drawing.Point(9, 172)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(28, 13)
		Me.Label6.TabIndex = 3
		Me.Label6.Text = "Text"
		'
		'Label7
		'
		Me.Label7.AutoSize = True
		Me.Label7.Location = New System.Drawing.Point(9, 198)
		Me.Label7.Name = "Label7"
		Me.Label7.Size = New System.Drawing.Size(28, 13)
		Me.Label7.TabIndex = 4
		Me.Label7.Text = "Text"
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(413, 318)
		Me.Controls.Add(Me.Label7)
		Me.Controls.Add(Me.Label6)
		Me.Controls.Add(Me.Panel1)
		Me.Controls.Add(Me.Label1)
		Me.Controls.Add(Me.TextBox1)
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.Panel1.ResumeLayout(False)
		Me.Panel1.PerformLayout()
		Me.Panel2.ResumeLayout(False)
		Me.Panel2.PerformLayout()
		Me.Panel3.ResumeLayout(False)
		Me.Panel3.PerformLayout()
		Me.Panel4.ResumeLayout(False)
		Me.Panel4.PerformLayout()
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub
	Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
	Friend WithEvents Label1 As System.Windows.Forms.Label
	Friend WithEvents Panel1 As System.Windows.Forms.Panel
	Friend WithEvents Panel2 As System.Windows.Forms.Panel
	Friend WithEvents Panel3 As System.Windows.Forms.Panel
	Friend WithEvents Panel4 As System.Windows.Forms.Panel
	Friend WithEvents Label5 As System.Windows.Forms.Label
	Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
	Friend WithEvents Label4 As System.Windows.Forms.Label
	Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
	Friend WithEvents Label3 As System.Windows.Forms.Label
	Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
End Class

Open in new window

Which produces the following output -Capture.JPG-saige-
0
 

Author Comment

by:RIAS
ID: 41769724
Thanks Sir!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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