CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Multiselect in Listbox

    I am using listbox control with Multiselect option set to Simple. Is it possible to restrict the number of items selected by the user? For example, I want user to select 5 items & if he try to select more, he should get a message that maximum items are selected and it should not be possible for him to select any more items. Is it possible to set the multiselect property at runtime?

  2. #2
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646
    Try this with a form containing listbox named list1:

    Private Sub List1_Click()
    If Me.List1.SelCount > 5 Then
    List1.Selected(List1.ListIndex) = False
    MsgBox "No way man! you have selected 5 item"
    End If
    End Sub

  3. #3
    Join Date
    Aug 2000
    Location
    india
    Posts
    191
    Thanks. The code serve the purpose.
    But, is there any way to set Multiselect at runtime?

  4. #4
    Join Date
    Jan 2003
    Location
    Albany, NY
    Posts
    82
    No- At run time time that property is read only. But if you set it to Extended at design time you can modify its behaviour with the code you have and the _MouseDown Event to SIMULATE any other mode.
    Your code can only be as good as your algorithm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured