Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Map an enumerated value to a set of OptionButton controls

Total Hit ( 2646)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


In VB6 and previous version, displaying an enumerated value in a group of option buttons is quite simple, provided that the option buttons be grouped in a control array. VB.NET doesn't support control arrays, so you can't reuse the same simple coding techniques. However, you can prepare a couple of helper procedure to make your job as easy as possible:

Click here to copy the following block
' set the RadioButton corresponding to the specified value
' sets the first RadioButton if the value is out of the valid range

Sub SetRadioButton(ByVal value As Integer, ByVal ParamArray ctrls() As _
  RadioButton)
  ' keep the value in correct range
  If value < 0 Or value >= ctrls.Length Then value = 0
  ctrls(value).Checked = True
End Sub

' return the index of the only selected RadioButton in a group
' returns -1 if no RadioButton is checked

Function GetRadioButton(ByVal ParamArray ctrls() As RadioButton) As Integer
  Dim value As Integer
  For value = 0 To ctrls.Length - 1
    If ctrls(value).Checked Then Return value
  Next
  Return -1
End Function

Here's how you can use these routines. Say that you have three RadioButton controls named rbuBlack, rbuGray, and rbuWhite and you want to use them to display a value from a variable that can be 0 (black), 1 (gray), or 2 (white).

Click here to copy the following block
' set the RadioButton corresponding to a color
Dim color As Integer = 1
SetRadioButton(color, rbuBlack, rbuGray, rbuWhite)
' ...

' retrieve the color set by the user
color = GetRadioButton(rbuBlack, rbuGray, rbuWhite)


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.