Subject: How to restrict the maximum number of possible sel
Posted By: lily611 Post Date: 11/18/2004 5:15:40 AM
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

Reply By: katsarosj Reply Date: 11/18/2004 9:12:51 AM
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
Reply By: lily611 Reply Date: 11/20/2004 12:11:45 AM
Thanks a lot , the second portion has worked out.



Go to topic 22397

Return to index page 711
Return to index page 710
Return to index page 709
Return to index page 708
Return to index page 707
Return to index page 706
Return to index page 705
Return to index page 704
Return to index page 703
Return to index page 702