Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, April 19, 2024 
 
Dynamically Populating Radio Buttons and Retrieving the Selected Value  
Description:  A method to populate radio buttons and retrieve their values in the SalesLogix development environment.

Category:  SalesLogix ActiveX Controls
Author:  Rick Smith
Submitted:  7/27/2005
   
Stats: 
Article has been read 18859 times

Rating: - 5.0 out of 5 by 3 users
 

fiogf49gjkf0d
Background

Developing a form in SalesLogix 6.1 Architect, I needed to dynamically populate a group of radio buttons. When a user selected one of the radio buttons, I then needed to obtain the value of that radio button. Seemed easy enough – VB6 provides the property .Value, but alas, the SLX development environment RadioGroup control lacks this property (why?!). The only property that indicates which radio button was selected is .ItemIndex, which is simply an integer (0,1,2,3) representing the radio buttons in the order displayed.


The Solution

I am populating this particular RadioGroup with some values from the PLUGINS table, specifically those where the Family filed contains ’Letters’. (I also had quite a challenge obtaining only the latest version of each Letter, but that’s a separate story...)

I first populate a recordset with the necessary fields:

Dim objCoverLetters ' Recordset to hold cover letters
Set objCoverLetters = CreateObject("ADODB.Recordset")
Dim strSelectCoverLetters
strSelectCoverLetters = "SELECT P.PLUGINID, P.NAME, P.MODIFIEDDATE " & _
                        "FROM SYSDBA.PLUGIN P " & _
                        "WHERE P.FAMILY = 'Letter'" & _
                        "AND P.USERID IN ('SYST00000001', 'ADMIN')"

objCoverLetters.Open strSelectCoverLetters, & _
    Application.GetNewConnection, adOpenForwardOnly, adLockReadOnly

The resulting Letter options will be displayed on a Form for the user to select. Presumably the user will make their choice in a short period of time, but since keeping an ADO recordset open indefinitely is bad coding practice, I needed a way to keep the PLUGINID values available after the recordset is closed. An array was the possible approach, as it doesn’t require an open connection and is relatively light in memory requirements (assuming the result set is small, which it is). The .GetRows method is very useful to quickly and easily place an entire recordset into an array. After populating the array with the recordset values, the recordset is closed. We then loop through the array and populate the Radio Group with the corresponding array value:

If objCoverLetters.Recordcount > 0 Then
    ' Use the .GetRows method of the Recordset to place all records into an array
    ' then, close the Recordset
    aryCoverLetters = objCoverLetters.GetRows
    objCoverLetters.Close
    Set objCoverLetters = Nothing
    Dim intUbound
    intUBound = UBound(aryCoverLetters, 2)
    ' Populate the radio group with the cover letters from the array
    ' The .ItemIndex property of the resulting radio group will correspond to
    ' the second dimension of the array. 
    ' E.g. aryCoverLetters.ItemIndex = aryCoverLetters( , integer)
    Dim intCounter
    For intCounter = 0 to intUBound
        rdoCoverLetters.Items.Add(aryCoverLetters(1, intCounter) & " (" & _
                                  FormatDateTime(aryCoverLetters(2, intCounter), vbShortDate) & ")")
    Next ' intCounter
    ' Set the ItemIndex to the first radio button
    rdoCoverLetters.ItemIndex = 0
Else
    MsgBox("There was a problem retrieving the cover letters. Please contact the system administrator.")
End If

The resulting RadioGroup control on the form is shown below:



When the user submits the form, I need the PLUGINID. The RadioGroup’s .ItemIndex property returns the index value of the selected radio button. Since the .ItemIndex of the RadioGroup corresponds to the second dimension of the in-memory array, it is easily retrieved as shown in the following code:

Dim strSelectedCoverLetterID ' String to hold cover letter id
Dim strSelectedCoverLetterName ' String to hold cover letter name
' Get the Cover Letter id and name from the array aryCoverLetters
' using the .ItemIndex property of the radio group
strSelectedCoverLetterID = aryCoverLetters(0, rdoCoverLetters.ItemIndex)
strSelectedCoverLetterName = aryCoverLetters(1, rdoCoverLetters.ItemIndex)


Wrapping it Up

Dynamically populating radio buttons is a fairly common approach and saves rebuilding forms when a new item needs to be added. The SalesLogix IDE doesn’t make it easy to get the value of the Radio Group item that the user has selected other than the .ItemIndex, which is confounding. This approach solved a very perplexing problem – at least for me! Perhaps there was some other way to accomplish this, but I sure couldn’t find it.

 

About the Author

  Rick Smith
Promega Corporation

buy lyrica uk

buy lyrica online india redirect buy lyrica online india
fiogf49gjkf0d
Rick Smith is the Director of eBusiness/CRM for Promega Corporation, a life-sciences company based in Madison, WI USA with >250 SalesLogix users worldwide.


View online profile for Rick Smith
 

[ back to top] [ send to a friend]  

Rate This Article you must log-in to rate articles. [login here] 
 
Please log in to rate article.
 

Comments & Discussion you must log-in to add comments. [login here] 
 
Author Article Comments and Discussion
Bob (RJ)Ledger

slxdeveloper.com Forum Top 10 Poster!

Re: Dynamically Populating Radio Buttons and Retrieving the Selected Value
Posted: 8/3/2005 7:19:20 AM
fiogf49gjkf0d
Slick! This is a great example of "building a control at RunTime". Unfortunately not all controls lend themselves to this approach.
 
 

       Visit the slxdeveloper.com Community Forums!
Not finding the information you need here? Try the forums! Get help from others in the community, share your expertise, get what you need from the slxdeveloper.com community. Go to the forums...
 



 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 4/19/2024 3:12:39 PM