Solved

CheckedListBox Visual Studio 2005 Visual Basic

Posted on 2010-11-09
3
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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