?
Solved

CheckedListBox Visual Studio 2005 Visual Basic

Posted on 2010-11-09
3
Medium Priority
?
559 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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