Results 1 to 9 of 9

Thread: [RESOLVED] Control arrays

  1. #1

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Resolved [RESOLVED] Control arrays

    I am Using Vb6 for quite a few years but new to vb.net.

    Vb.net does not have control arrays .


    Control arrays provided :


    1. adding controls to an array at runtime .

    2. Removing controls From an array at runtime .

    3. changing properties of the controls by looping through the array.

    4. using a single procedure event for all the members of the control array.


    What is the best method to implement this In vb.net
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control arrays

    The question of control arrays is a well worn one around here, so forum search should yield quite a few results. I did find a couple of articles on MSDN just the other day that may be of interest to you and others on the subject.

    http://msdn.microsoft.com/library/de...visualcnet.asp
    http://msdn.microsoft.com/library/de...trolarrays.asp

  3. #3
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Control arrays

    Yeah, have a search on this site because as jmcilhinney said, it's been done to death. They were convenient but after a while you do find better ways around them. However, if you've searched and the info hasn't helped, then feel free to continue your pursuit here and I'll help you out.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Control arrays

    In .net you can have an array of anything you want. Fact. Controls are just classes like anything else.

  5. #5

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Re: Control arrays

    Thanks jmcilhinney . I read the msdn link.

    But i have a problem.

    Lets say . I have a requirement where label controls need to be added at runtime and i don't know beforehand that how many will be required and
    ofcourse what their name be.

    If we see this code :


    Private Sub AddEmailAddress()
    Dim txtEmail As New TextBox
    Dim lblEmail As New Label
    ' Set the desired properties
    txtEmail.Top = txtAddress.Top + txtAddress.Height + 10
    txtEmail.Left = txtAddress.Left
    lblEmail.Text = "Email"
    lblEmail.Location = New Point(lblAddress.Location.X, _
    txtEmail.Location.Y)
    ' Add to the collection
    tpAddress.Controls.Add(txtEmail)
    tpAddress.Controls.Add(lblEmail)

    AddHandler txtEmail.Enter, AddressOf ProcessEnter

    End Sub


    adding controls at runtime and creating their event handlers is Fine , But i don't know what purpose this code will solve.

    Because If i know i have to add A textbox and A label , i would not do that at runtime .

    I want to add controls at runtime and their number can depend on a variable.

    How to do that ?
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control arrays

    Use a loop and do this the number of times that your variable prescribes. You will presumably need to have some method of setting their Location based on the value of the loop counter. You can add these controls to an array or collection, other than the form's Controls collection, as they are created if you want. You can then access them using that array or collection without having to allow for the other controls on the form.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Control arrays

    Hi,

    Control Arays have NOT dissapeared from .NET. It is the Control Index Number property which is no longer available.

    The following thread in the forum code bank gives you all you are asking for.

    http://www.vbforums.com/showthread.php?t=328100
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Re: Control arrays ( Resolved )

    Thanks taxes.

    That was exactly what i was looking for.
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: [RESOLVED] Control arrays

    Glad to have helped. Sorry I did not see your post sooner
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width