Solved

CheckedListBox Visual Studio 2005 Visual Basic

Posted on 2010-11-09
3
556 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 tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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