Results 1 to 14 of 14

Thread: Why doesn't .NET support control arrays

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Why doesn't .NET support control arrays

    What is it about .NET that won't let it support an array of objects?WHat is the purpose of leaving out this functionality?
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    An array of objects?

    Dim a() As Object

    An array of controls?

    Dim ctrl() As Textbox
    'or if they exist already
    Dim ctrl() As TextBox={TextBox1,TextBox2,TextBox3}

    And as far as events go why not just add more controls to the same event handle. If this is something you'll need to do often then just make a macro to speed up the process.

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click, Button3.Click, Button2.Click, Button1.Click

    I don't see that any functionality was lost in fact I'd say we gained some. Now you can have controls of different types act the same as a control array.

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yah one control can handle events from multiple controls, but how do you know which control was clicked?

    With a control array you could find out by getting the index....msgbox Button(Index). But how do you do that with .Net?
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Generally the sender argument is the control that is raising the event.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. If TypeOf (sender) Is Button Then
    2.             Dim c As Button
    3.             c = sender
    4.             MsgBox(c.Name)
    5.         End If

  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    thanks, that seems to work fine.

    One other question, why is the name property not in the Sender list?

    If you type msgbox Sender. there is only GetType there is no Name property.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Because the sender may not have a name property. I know, sounds ludicrous... but i think it has more to do with being able to have any object raise the event, and not all objects have the same properties, so you need a layer of abstraction in there.

  8. #8
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by Arc
    thanks, that seems to work fine.

    One other question, why is the name property not in the Sender list?

    If you type msgbox Sender. there is only GetType there is no Name property.
    Not all the objects have a name property. If you just type MessageBox.Show(Sender.Name), then if the object has a name property it should show you.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by nemaroller
    Because the sender may not have a name property. I know, sounds ludicrous... but i think it has more to do with being able to have any object raise the event, and not all objects have the same properties, so you need a layer of abstraction in there.
    Didn't mean to repeat you!
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  10. #10

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Makes sense I guess... but it makes it difficult to figure out on your own
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Considering we both posted at the same time, it could have easily concluded with your message being posted first. But as it turns out, I won!!!!

    HARARHAR!

  12. #12
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by nemaroller
    VB Code:
    1. If TypeOf (sender) Is Button Then
    2.             Dim c As Button
    3.             c = sender
    4.             MsgBox(c.Name)
    5.         End If
    just a little comment on this: I dont think there is a need to check the type of the object (unless ofcourse the sub handles events for different types of objects). Umm also if option strict is on, c = sender wouldn't work I think it's a better coding practice to convert it even if option strict is off

    I would use c=DirectCast(sender, Button)
    (I think directCast works faster than Ctype )
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Umm also if option strict is on, c = sender wouldn't work I think it's a better coding practice to convert it even if option strict is off


    Yea... well in my race against Lunatic, I skipped that part

  14. #14
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by nemaroller
    Umm also if option strict is on, c = sender wouldn't work I think it's a better coding practice to convert it even if option strict is off


    Yea... well in my race against Lunatic, I skipped that part
    hehe I think Arc would figure it out anyways

    oh btw I announce you the winner of this so called "race", congratulations
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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