Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2004, 06:15 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to restrict the maximum number of possible sel

Hi,
How to restrict the maximum number of possible selections in a multiple list box or drop-down list in .Net.
In my application i have to restrict the maximum selection must not be greater than 3 from the dropdown list.

Regards
Lily

 
Old November 18th, 2004, 10:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Is this a Windows form or a Web form? If it is a Windows, it is easy:

----------------------------------------------------

If ListBox1.SelectedItems.Count > 3 Then
     MessageBox.Show("Too many selections.")
Else
     MessageBox.Show("Your selection count is fine.")
End If

----------------------------------------------------

I could be wrong, but I don't believe there is a SelectedItems Count property in a web form, so you could do something like this:

----------------------------------------------------

Dim intCntr As Int32 = 0
Dim itm As ListItem

For Each itm In ListBox1.Items
   If itm.Selected = True Then
      intCntr += 1
   End If
Next

If intCntr > 3 Then
   Label1.Text = "Too many selections."
Else
   Label1.Text = "Your selection count is fine."
End If

----------------------------------------------------

J
 
Old November 20th, 2004, 01:11 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot , the second portion has worked out.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Maximum Number of Controls? Aaron Edwards Visual Studio 2005 0 March 3rd, 2007 06:04 PM
maximum number of prefixes? gumgak ASP.NET 1.0 and 1.1 Basics 5 February 13th, 2006 09:56 AM
How to restrict the maximum number of possible sel lily611 ASP.NET 1.0 and 1.1 Basics 1 October 30th, 2004 07:57 PM
find maximum number Abhinav_jain_mca SQL Server 2000 4 September 28th, 2004 08:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.