PC Review


Reply
Thread Tools Rate Thread

How can we define control array in VB.Net

 
 
Sarfaraz Khan
Guest
Posts: n/a
 
      18th Aug 2004
Hello,
anyone can guid me how we can handle and define control array in vb.net?

Thanks & regards

SARFARAZ KHAN


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      18th Aug 2004
* "Sarfaraz Khan" <(E-Mail Removed)> 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.gbl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
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?
>



 
Reply With Quote
 
Christopher W. Douglas
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> anyone can guid me how we can handle and define control array in vb.net?
>
> Thanks & regards
>
> SARFARAZ KHAN
>
>



 
Reply With Quote
 
Matthew Dill
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> anyone can guid me how we can handle and define control array in vb.net?
>
> Thanks & regards
>
> SARFARAZ KHAN
>
>



 
Reply With Quote
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      18th Aug 2004

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

>

<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.)


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      18th Aug 2004
* "Jeff Johnson [MVP: VB]" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Sarfaraz khan
Guest
Posts: n/a
 
      19th Aug 2004
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!
 
Reply With Quote
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      19th Aug 2004

"Sarfaraz khan" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

> 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.


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      19th Aug 2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to define struct with array in C#? Polaris Microsoft C# .NET 2 13th Mar 2008 12:22 PM
How to Define and Use a Dynamic Array Chaplain Doug Microsoft Excel Programming 5 4th Dec 2007 09:19 PM
How to define array ? =?Utf-8?B?SmFyb2Q=?= Microsoft VB .NET 2 23rd Oct 2004 05:39 PM
Define an array Charles Microsoft Excel Worksheet Functions 17 8th Oct 2004 03:10 AM
Define datacolumn array Bucket Microsoft VC .NET 0 9th Jul 2003 04:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 PM.