Solved

CheckedListBox Visual Studio 2005 Visual Basic

Posted on 2010-11-09
3
543 Views
Last Modified: 2012-05-10
I have a checkedListBox that has 14 choices that can be checked by the user.
I would like the end user to be able to select any of the 14 choices but be limted to
6 in total to be checked.  
I do not know how to allow for only 6 boxes to be checked in the CheckedListBox
while allowing for any of the 14 to be selected from.
0
Comment
Question by:dastaub
3 Comments
 
LVL 2

Expert Comment

by:AarthiPrabakaran
ID: 34099621
Hi sample sol:


<asp:HiddenField ID="hiddenChkCount" runat="server" Value="0" />


<script type="text/javascript">function chkCount(obj){    if(obj.checked==true)    {        if( document.getElementById( '<%=hiddenChkCount.ClientID %>' ).value >= 6 )        {            alert('You cannot select more than 6 items.');            obj.checked=false;        }        else        {            document.getElementById( '<%=hiddenChkCount.ClientID %>' ).value = parseInt( document.getElementById( '<%=hiddenChkCount.ClientID %>' ).value ) + 1;        }    }    else    {        document.getElementById( '<%=hiddenChkCount.ClientID %>' ).value = parseInt( document.getElementById( '<%=hiddenChkCount.ClientID %>' ).value) - 1;    }}</script>
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 34099636
That's for ASP.NET. For VB right click on the CheckedListBox and hit view code. Then add the ItemCheck event handler and make it look something like this
   
 Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        If CheckedListBox1.CheckedIndices.Count >= 6 Then
            e.NewValue = CheckState.Unchecked
        End If
    End Sub

Open in new window

0
 

Author Closing Comment

by:dastaub
ID: 34113916
thank you
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question