Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Thursday, October 10, 2024 
 
The SalesLogix CheckListBox Control  
Description:  The SalesLogix CheckListBox control is used to display a scrollable list. Similar to the ListBox control, except that each of the items has a checkbox next to it. This article outlines how to use the CheckListBox control and determine which items the user has checked.

Category:  SalesLogix ActiveX Controls
Author:  Kris Halsrud
Submitted:  10/7/2005
   
Stats: 
Article has been read 16118 times

Rating: - 5.0 out of 5 by 9 users
 

fiogf49gjkf0d
The SalesLogix CheckListBox Control

The CheckListBox control is used to display a scrollable list. Similar to the ListBox control, except that each of the items has a checkbox next to it. If the number of items in the list exceeds the size of the CheckListBox window a vertical scroll bar automatically appears. The following shows an example of the CheckListBox:



The CheckListBox control has the advantage of allowing a multiple items to be easily selected within a list by a user for some purpose. While the CheckListBox control does have ease of use going for it, it does have limitations. The list is intended to store only one thing, the display text. Storing any sort of ID corresponding to that item is harder to do. Because of this, lists with items that may have duplicate values like, account names, can be hard to determine which record was selected. In the example CheckListBox above the product list is shown along with the appended actualid value for that product. This is one method for being able to retrieve a corresponding ID. These values could also be moved to the far right outside the scope of the visible list making them invisible to the end user.

With this limit in mind, other controls, such as DataGrids may be more useful in certain conditions.

In this article we will discuss two methods of using the CheckListBox, how to fill the list, and how to determine which items were checked by a user.

Filling the list is similar to many other controls, including ComboBoxes or ListBoxes. By using the CheckListBox.Items.Add method we can loop through and enter in as many items as needed into the list. The following code accomplishes this step:

CheckListbox1.Clear

First we must clear the CheckListBox control of any current values.

Set objRS = GetFields("name, actualid", "product", "1=1 order by name")
With objRS
    While Not (.BOF Or .EOF)

Next we get a list of items to fill the CheckListBox with. In our sample we will use a record set returned using the output of the standard SalesLogix function GetFields/ This function has retrieved the tow fields of NAME and ACTUALID from the PRODUCT table and also ordered the record set alphabetically by the NAME field. We then loop through the record set as long as we have data to loop through.

CheckListbox1.Items.Add .Fields("name").Value & "- *{" & .Fields("actualid").Value & "}*"

Within our loop we then call the CheckListBox control’s Item.Add method to add an item to the list. In our case we are adding the NAME of the product and then the ACTUALID field wrapped in a formatted string of "*{…}*".

.MoveNext


After adding the record to the list, we move to the next record in the record set

Wend
.Close
End With
Set objRS = Nothing

After looping through the entire record set we then close the record set and perform cleanup to destroy the record set object and free up the resources used by it.

Lets see the entire code now:

CheckListbox1.Clear
Set objRS = GetFields("name, actualid", "product", "1=1 order by name")
With objRS
    While Not (.BOF Or .EOF)
        CheckListbox1.Items.Add .Fields("name").Value & "- *{" & .Fields("actualid").Value & "}*"
        .MoveNext
    Wend
.Close
End With
Set objRS = Nothing


Determining Checked Items

Now that the CheckListBox has been filled, the user can now select the items they wish. The next procedure we will look at is how to tell what records a user selected.

We can use the CheckListBox Items.Count property to find out how many items are in the list. Then looping through list and using the CheckListBox.Checked property will allow us to see which items are selected.

For i = 0 to CheckListBox1.Items.Count- 1

Using a For…Next loop in conjunction with the CheckListBox.Items.Count property allows us to loop through the entire list control. Inside this loop we will check to see which items are selected, if any.

If CheckListBox1.Checked(i) = True then
    Msgbox CheckListBox1.Items.Item(i)
End If

Checking to see if the current item by index value is checked we can see which items are chosen by the user. Inside this If statement, we can do our actions based on the selected items like adding the chosen records to a record set or inserting them into another table. In our sample we are simply using displaying the text of the items selected in a message box, using the CheckListBox.Items.Item property which returns the displayed text of the item in the list.

Next

Finally we Complete our For…Next loop. Lets see the completed code now.

For i = 0 to CheckListBox1.Items.Count- 1
    If CheckListBox1.Checked(i) = True then
        Msgbox CheckListBox1.Items.Item(i)
    End If
Next

Pretty simple. This control also exposes some properties for setting appearances as well as a few events to run off of,: WhenClick, WhenClickCheck, WhenDblClick, and OnKeyPress.

 

About the Author

Kris Halsrud
(SalesLogix Business Partner)
Customer FX Corporation

fiogf49gjkf0d


View online profile for Kris Halsrud
 

[ 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
Ryan Farley

slxdeveloper.com Site Administrator
slxdeveloper.com Forum Top 10 Poster!

Re: The SalesLogix CheckListBox Control
Posted: 10/7/2005 4:05:55 PM
fiogf49gjkf0d
Great stuff Kris. It's about time we get some of the SLX controls "documented" ;-)

-Ryan
 
Mike Boysen



Re: The SalesLogix CheckListBox Control
Posted: 10/8/2005 5:20:31 PM
fiogf49gjkf0d
Uhhhh. There's a checklistbox control?
 
Bob (RJ)Ledger

slxdeveloper.com Forum Top 10 Poster!

Re: The SalesLogix CheckListBox Control
Posted: 10/17/2005 6:13:17 PM
fiogf49gjkf0d
Cool. Nice writeup Chris.
 
Vitaly Lidov
 

Re: The SalesLogix CheckListBox Control
Posted: 12/28/2005 10:42:40 AM
fiogf49gjkf0d
Very helpful.
At least can extrapolate on other list conttrols.

VL
 
Paul Scott
 

Re: The SalesLogix CheckListBox Control
Posted: 4/6/2012 1:08:38 PM
fiogf49gjkf0d

Thanks for Posting this.


Where in a form would you grab the user input from the checkedlistbox and write it back into the db?


Also, and this is only related, is there some what to Add something to the on click event for the checkedlistbox to tell the form that changes have been made and to enable the save and undo button?


Thank you for your time.


-Paul

 
 

       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): 10/10/2024 2:20:31 AM