Results 1 to 25 of 25

Thread: Control Arrays

Hybrid View

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

    Re: Control Arrays

    However, you have to add further code in order to make controls in the control array respond to events.
    I don't live here any more.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Control Arrays

    Quote Originally Posted by wossname
    However, you have to add further code in order to make controls in the control array respond to events.

    Hi, My apologies. I should have selected the full coding when I cut it from a programme.
    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.

  3. #3
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: Control Arrays

    Okay.... so where is the rest of the code?

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Control Arrays

    Quote Originally Posted by epixelman
    Okay.... so where is the rest of the code?

    It's all there.

    You have an array of TextBoxes together with an event handler which responds to any text change in any one of them. If you want to handle other events the example should be easy to follow.

    What is your specific problem?
    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.

  5. #5
    Member
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    55

    Re: Control Arrays

    Thanks for the explanation Taxes, but is it possible to add a handler to the control array itself?

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Control Arrays

    Quote Originally Posted by trezise
    Thanks for the explanation Taxes, but is it possible to add a handler to the control array itself?
    No. But what is your problem? You have one eventhandler to handle the same event (e.g. TextChanged) which handles ALL the textboxes. If you are creating the array in the designer, then you have to add the handle for each textbox, but if you create them in code, the appropriate handle is added each time you create the TextBox
    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.

  7. #7
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Control Arrays

    Hmm. I guess I can understand the want for this, if this is a style you're used to. However, never having had a "control Array" I don't like it. I'm not saying you suck or your code sucks or it's dumb or whatever, but for me, who took one look at VB5 and said "Screw VB" until I saw VB.NET, It just doesn't sit in my belly too well. If I had to do this, I would probably use an arraylist. Ever since the first day I used an arraylist, the word "ReDim" makes me ill.

    To me, Arrays are just poor for any kind of dynamic resizing in vb.net. Also, ReDim doesn't work with all dimensions of multi-dimensional arrays. (not cool to me) Honestly, I really don't see the need to have the array of controls.
    Use of the tag property, as you mentioned, is a more efficient method in my opinion. You've already got a collection of controls you can enumerate through (Me.Controls) and using the tag property can easily identify them as part of a group.

    i.e,

    VB Code:
    1. For i As Integer = 1 to 10
    2.     WithEvents T as new TextBox
    3.     T.Location = New Point(0,i*10)
    4.     T.Size = New Size(200,25)
    5.     T.Tag = "GUITextBoxes" 'or whatever.
    6.     Me.Controls.Add(T)
    7. Next i
    8.  
    9. 'and
    10.  
    11. For Each Ctl As Control In Me.Controls
    12.     If TypeOf(Ctl) Is TextBox AndAlso DirectCast(Ctl,TextBox).Tag = "GUITextBoxes" Then
    13.        DirectCast(Ctl,TextBox).Text = "I'm a dynamically Created TextBox"
    14.     End If
    15. Next Ctl

    So, you can still enumerate through them easily, still add handlers (using the same method you did by casting Sender) and If you want to add another one later, it's no big deal - just add the same tag property, and your current enumeration routines still work.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

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