By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

How can we define control array in VB.Net

P: n/a
Hello,
anyone can guid me how we can handle and define control array in vb.net?

Thanks & regards

SARFARAZ KHAN
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
* "Sarfaraz Khan" <sa******@alghanem.net> scripsit:
anyone can guid me how we can handle and define control array in vb.net?


<URL:http://groups.google.de/groups?selm=%23TBRYhyaEHA.904%40TK2MSFTNGP09.phx.g bl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
Sarfaraz,

Dim ctrArea As Control() = New Control() {me, Button1, Etc}

I think you are not after that, however than you have to tell more?

Cor
anyone can guid me how we can handle and define control array in vb.net?

Nov 21 '05 #3

P: n/a
Sarfaraz,

If you mean adding controls dynamically to a form, you do it in the code:

Create a control object at the module level (before the Windows Form
Designer generated code):

Private MyLabel as Label

Then, after InitializeComponent, or in the Load event, set the position and
visibility of the control and add it to the Controls collection of the Form:

With MyLabel
.Top = 40
.Left = 40
.Visible = True
End With
Me.Controls.Add(MyLabel)

That's it. Now, to have an ARRAY of controls, create an array at the module
level:

Private MyLabels as Label()

Then in the Load event, execute similar code for each of the objects in the
array:

Dim i as Integer

ReDim MyLabels(9)
For i = 0 To 9
MyLabels(i) = New Label
With MyLabels(i)
.Top = (i * 40) + 40
.Left = 40
.Visible = True
End With
Me.Controls.Add(MyLabels(i))
Next i

In order to change your control later in the form, just call your
module-level object:

MyLabels(5).Text = "Some New Text"

Hope this helps.
--
Christopher W. Douglas
SRS Technologies, Inc.
christopher (dot) douglas (at) srs (dot) com
"Sarfaraz Khan" <sa******@alghanem.net> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
Hello,
anyone can guid me how we can handle and define control array in vb.net?

Thanks & regards

SARFARAZ KHAN

Nov 21 '05 #4

P: n/a
If you are trying to create a common handler for a series of controls you
can modify the handle statement(s) at the end of each event handler:

For example:
Private Sub TextBox1_TextChanged(ByVal sender as System.Object, ByVal e
As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged,
TextBox3.TextChanged etc.

Dim ltxtBox as TextBox
ltxtBox = CType(sender, TextBox)

Select Case ltxtBox.Name
Case "TextBox1"
'do something
Case "TextBox2"
'do something
End Select

End Sub

"Sarfaraz Khan" <sa******@alghanem.net> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
Hello,
anyone can guid me how we can handle and define control array in vb.net?

Thanks & regards

SARFARAZ KHAN

Nov 21 '05 #5

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

<URL:http://groups.google.de/groups?selm=...K2MSFTNGP09.ph
x.gbl>

"In VS.NET 'Whidbey' (2005) control arrays will be supported natively"? I
hadn't heard about that. where might I find info on this particular subject?
Is it as simple as cracking open the scaled-down MSDN that came with the
beta and looking up "control array"? (I don't have the VPC that I'm running
Whidbey in up at the moment, nor even the computer that runs it, or I'd
check myself.)
Nov 21 '05 #6

P: n/a
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
<URL:http://groups.google.de/groups?selm=...K2MSFTNGP09.ph
x.gbl>

"In VS.NET 'Whidbey' (2005) control arrays will be supported natively"? I
hadn't heard about that. where might I find info on this particular subject?


I remember there was support in the PDC build, but I didn't check that
in the newer builds.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

P: n/a
replacement of these code into VB.Net?

Private Sub Command1_Click(index as integer)
Select Case index
Case 0
'Some Code
Case 1
'Some Code

End Select
End Sub
and how i place control on the form that make automaticaly control array
like in VB 6

Thank & Regards
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #8

P: n/a

"Sarfaraz khan" <nu*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
replacement of these code into VB.Net?

Private Sub Command1_Click(index as integer)
Select Case index
Case 0
'Some Code
Case 1
'Some Code

End Select
End Sub
Private Sub CommonButtonClickHandler(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles AddButton.Click, DeleteButton.Click[, ...]
If sender Is DeleteButton Then
' Do something
ElseIf sender Is AddButton Then
' Do something else
[etc.]
End If
End Sub
and how i place control on the form that make automaticaly control array
like in VB 6


You don't. .NET has done away with the VB6 concept of control arrays.
Nov 21 '05 #9

P: n/a
Sarfaraz,
and how i place control on the form that make automaticaly control array
like in VB 6

As Jeff stated you can not do it the same way, however you can place your
control in every array and than process it like that. A simple one
\\\
Dim ctrArr as new Arraylist
ctrArr.Add(myButton1)
dim buttonname as string = directcast(ctrArr(0),button).name
///

So you can make as much controlarrays as you want.

I hope this helps?

Cor
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.