4 Replies - 325 Views - Last Post: 19 March 2012 - 05:49 AM Rate Topic: -----

#1 Sgt. Cookie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 12

Question: Is it possible to "mass select" several unconnected

Posted 19 March 2012 - 04:37 AM

The objects I am trying to mass select are text boxes, and I am trying to select them all, without tediously selecting all of them, to see if any are blank and place in a 0 if any are.

Is there a way to do that?
Is This A Good Question/Topic? 0
  • +

Replies To: Question: Is it possible to "mass select" several unconnected

#2 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Re: Question: Is it possible to "mass select" several unconnected

Posted 19 March 2012 - 04:55 AM

are you developing an application or website ?

There are numerous ways of doing that .

Well , an easy way that i prefer is to iterate through all controls on the form

        Dim cCtrl As Control

        For Each cCtrl in Form1.Controls
            If (TypeOf cCtrl Is TextBox)  Then
               If cCtrl.Text = "" then
                   cCtrl.Text = "0"
                End If
            End If
        Next 


This post has been edited by shadachi: 19 March 2012 - 05:07 AM

Was This Post Helpful? 2
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Question: Is it possible to "mass select" several unconnected

Posted 19 March 2012 - 04:59 AM

if you want to see if any of textbox is blank you can check like this
If textbox1.text="" then ...

if you want to select whole text in textbox you do it like this:
textBox1.Selectionstart = 1
textBox1.SelectionLength = textBox1.Text.ToString().Length
textBox1.Focus()


if you want to do this programmatically for a lots of textboxes than put all textboxes to List Of textboxes. Than you can loop through list and do what you want.
Public Class Form1
    Private txtBoxes As New List(Of TextBox)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtBoxes.Add(TextBox1)
        txtBoxes.Add(TextBox2)
        txtBoxes.Add(TextBox3)

        For Each txtBox As TextBox In txtBoxes
            If txtBox.Text = "" Then txtBox.Text = 0
        Next
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#4 Sgt. Cookie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 12

Re: Question: Is it possible to "mass select" several unconnected

Posted 19 March 2012 - 05:07 AM

View Postshadachi, on 19 March 2012 - 04:55 AM, said:

are you developing an application or website ?


This is an application, sorry.

I tried your method, but when I replace the Form1 it underlines the actual name, and when I mouse over it says that there is a syntax error.
Was This Post Helpful? 0
  • +
  • -

#5 Sgt. Cookie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 12

Re: Question: Is it possible to "mass select" several unconnected

Posted 19 March 2012 - 05:49 AM

Apologies for the double post. No edit button...


Apart from having to add "Me." to cControl, it works perfectly. Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1