Solved

CheckedListBox Visual Studio 2005 Visual Basic

Posted on 2010-11-09
3
532 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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now