Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Go Back  Xtreme Visual Basic Talk > > > Control Arrays - a very nasty Kludge


Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2014, 05:03 AM
bobcory's Avatar
bobcory bobcory is offline
Contributor
 
Join Date: Jun 2003
Location: NW UK
Posts: 454
Question Control Arrays - a very nasty Kludge


Well, I have spent 8 months converting my project from VB6 to vb.net. Of all the irritating things (and there have been plenty), the worst is the decision by MS to "improve" things by eliminating Control Arrays

Yes, they tell you how to get round this eg here:

http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx

and if I had a spare month, maybe I could do this BUT I have a form with over 100 controls, all of which are arrays of RadioButtons, CheckBoxes etc. So, I decided to Kludge It (people do all sorts of disgusting things in the privacy of their own homes)

Let's take RadioButtons as an example. On the form I call them radMode01 etc then, on form load, I do this:

Code:
  Dim radBox(9) As RadioButton

  radBox(1) = radButton01
  radBox(2) = radButton02
  radBox(3) = radButton03
  radBox(4) = radButton04
  radBox(5) = radButton05
  radBox(6) = radButton06
  radBox(7) = radButton07
  radBox(8) = radButton08
  radBox(9) = radButton09
Now, what is truly wonderful about this is that if you alter one it changes the other and vice versa - they are directly mapped (thank you Microsoft). So

Code:
  radBox(5).Checked = True
  MsgBox(radButton05.Checked.ToString)          ' Gives "True"
  radButton07.Checked = True
  MsgBox(radBox(7).Checked.ToString)          ' Gives "True"
To get the index I use another Kludge

Code:
  intIndex = Cint(Strings.Right(strName, 2))
So, I hope this helps somebody (you don't have to tell anybody you did it)

Maybe there is an easier way?
__________________
MOPEKS - a freeware program that generates programs that use each other to solve problems. Is this the correct route to a genuinely intelligent machine?
.
Reply With Quote
  #2  
Old 10-15-2014, 11:23 AM
Gruff's Avatar
GruffControl Arrays - a very nasty Kludge Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Bob,

These days I mostly create my control arrays at run time.
This means I do not need to manually draw them at design time.

I usually use a list(of <control type>) instead of an array as it allows me to add or remove control at any time during run time.

I also use addhandler to add controls to events at run time. Any of my control group clicked fires the same event.

Speaking of which you can also add handlers at design-time.
You just add to the 'Handles' clause at the end of the event.

Code:
Public Class Form1 ' Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) _ Handles Button1.Click, Button2.Click, Button3.Click Dim sName As String = CType(sender, Button).Name Select Case sName Case "Button1" 'Do something here Case "Button2" 'Do something here Case "Button3" 'Do something here End Select End Sub End Class

Finally I tend to make control arrays inside of usercontrols because I can then reuse them from project to project.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply

Tags
control arrays


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
 
Control Arrays - a very nasty Kludge
Control Arrays - a very nasty Kludge
 
-->