Click here to Skip to main content
15,908,172 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: ASP.Net? Pin
Christian Graus9-Jul-07 0:54
protectorChristian Graus9-Jul-07 0:54 
Questionhow to create control array ? in vb .net Pin
babusat8-Jul-07 18:24
babusat8-Jul-07 18:24 
AnswerRe: how to create control array ? in vb .net Pin
Tom Deketelaere8-Jul-07 21:42
professionalTom Deketelaere8-Jul-07 21:42 
QuestionRe: how to create control array ? in vb .net Pin
babusat9-Jul-07 0:11
babusat9-Jul-07 0:11 
AnswerRe: how to create control array ? in vb .net Pin
Tom Deketelaere9-Jul-07 0:35
professionalTom Deketelaere9-Jul-07 0:35 
Questionits good but i want to access textbox with index value Pin
babusat9-Jul-07 2:41
babusat9-Jul-07 2:41 
AnswerRe: its good but i want to access textbox with index value Pin
Tom Deketelaere9-Jul-07 3:14
professionalTom Deketelaere9-Jul-07 3:14 
AnswerRe: how to create control array ? in vb .net Pin
TwoFaced9-Jul-07 8:48
TwoFaced9-Jul-07 8:48 
There is no design time support for creating control arrays. Here is some code that demonstrates a few different approaches.
Public Class Form1
    ' An array of textbox's
    Private ControlArray As New List(Of TextBox)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Here I am adding TextBox's that already exist on my form to the array
        With ControlArray
            .Add(TextBox1)
            .Add(TextBox2)
            .Add(TextBox3)
        End With

        ' Loop through each textbox in the array
        For Each tb As TextBox In ControlArray
            MsgBox(tb.Name)
        Next

        ' Access a textbox by index
        MsgBox(ControlArray(1).Name)

        ' Here I am creating textboxes dynamically and adding them
        ' to the array
        For i As Integer = 0 To 2
            ' Create a textbox
            Dim tb As New TextBox
            ' Set it's position
            tb.Location = New Point(20, 10 + i * 30)
            ' Set it's width
            tb.Width = 100

            ' Add the textbox to the array
            ControlArray.Add(tb)

            ' Add the textbox to the form
            Me.Controls.Add(tb)

            ' Add handlers for the GotFocus and LostFocus events
            AddHandler tb.GotFocus, AddressOf TextBox_GotFocus
            AddHandler tb.LostFocus, AddressOf TextBox_LostFocus
        Next

        ' Here I've looped through the forms controls and found
        ' all the textboxes and added them to the array
        ' This is a good approach if you have many controls you added at
        ' design time but don't want to manually add each one to the array.
        ' The desired event handlers can also be dynamically added this way
        For Each ctrl As Control In Me.Controls
            Dim tb As TextBox = TryCast(ctrl, TextBox)
            If tb IsNot Nothing Then
                ControlArray.Add(tb)
            End If
        Next
    End Sub

    ' Handles the textboxes GotFocus event
    ' I've handled the controls I created at design time by including them after the handles keyword
    Private Sub TextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox3.GotFocus
        ' tb is a reference to the textbox that raised this event
        Dim tb As TextBox = DirectCast(sender, TextBox)
        tb.BackColor = Color.Wheat
    End Sub

    ' Handles the textboxes LostFocus event
    ' I've handled the controls I created at design time by including them after the handles keyword
    Private Sub TextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus, TextBox2.LostFocus, TextBox3.LostFocus
        ' tb is a reference to the textbox that raised this event
        Dim tb As TextBox = DirectCast(sender, TextBox)
        tb.BackColor = Color.White
    End Sub
End Class

Questionhow to create control array ? in vb .net Pin
babusat9-Jul-07 18:20
babusat9-Jul-07 18:20 
AnswerRe: how to create control array ? in vb .net Pin
TwoFaced9-Jul-07 19:51
TwoFaced9-Jul-07 19:51 
QuestionMe.ActiveControl.Name does not display any name Pin
babusat9-Jul-07 23:30
babusat9-Jul-07 23:30 
AnswerRe: Me.ActiveControl.Name does not display any name Pin
TwoFaced10-Jul-07 5:18
TwoFaced10-Jul-07 5:18 
QuestionSort the data in a DataGrid Pin
atlasliu8-Jul-07 17:38
atlasliu8-Jul-07 17:38 
AnswerRe: Sort the data in a DataGrid Pin
Rupesh Kumar Swami8-Jul-07 19:25
Rupesh Kumar Swami8-Jul-07 19:25 
QuestionHow to get "ID" from a DataGrid? Pin
atlasliu8-Jul-07 17:36
atlasliu8-Jul-07 17:36 
AnswerRe: How to get "ID" from a DataGrid? Pin
Tom Deketelaere8-Jul-07 21:47
professionalTom Deketelaere8-Jul-07 21:47 
Questionhow do I disable buttons if first row selected in DataGridView? Pin
matt_in_oz8-Jul-07 17:33
matt_in_oz8-Jul-07 17:33 
AnswerRe: how do I disable buttons if first row selected in DataGridView? Pin
Thomas Chester9-Jul-07 8:25
Thomas Chester9-Jul-07 8:25 
GeneralRe: how do I disable buttons if first row selected in DataGridView? Pin
matt_in_oz9-Jul-07 17:21
matt_in_oz9-Jul-07 17:21 
QuestionAbsolutely Desperate...MAPI anyone Pin
EvScott8-Jul-07 9:08
EvScott8-Jul-07 9:08 
AnswerRe: Absolutely Desperate...MAPI anyone Pin
The ANZAC8-Jul-07 17:14
The ANZAC8-Jul-07 17:14 
GeneralRe: Absolutely Desperate...MAPI anyone Pin
EvScott9-Jul-07 3:59
EvScott9-Jul-07 3:59 
QuestionApproximation Pin
magedhv8-Jul-07 0:03
magedhv8-Jul-07 0:03 
AnswerRe: Approximation Pin
Luc Pattyn8-Jul-07 0:09
sitebuilderLuc Pattyn8-Jul-07 0:09 
GeneralRe: Approximation Pin
magedhv8-Jul-07 0:49
magedhv8-Jul-07 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.