News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

List control when the user clicks the list but not on any item

Started by nandagopal, May 20, 2009, 07:19 PM

Previous topic - Next topic

nandagopal

Normally you cannot deselect all items in a ListBox once you have selected one. This example shows one way to let the user deselect all items.

When you click on an item, you see these events:

    * MouseDown
    * Click
    * MouseUp

When you click off the items, you see these events:

    * MouseDown
    * MouseUp

The trick is to determine whether you received a Click event.

In the Click event handler, set a Boolean variable indicating that a Click occurred. Then in the MouseUp event, see if it follows a Click.


Private m_ListClicked As Boolean

Private Sub List1_Click()
    m_ListClicked = True
End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    If Not m_ListClicked Then
        ' The user clicked off of all items.
        List1.ListIndex = -1
    Else
        m_ListClicked = False
    End If

    lblSelected.Caption = List1.Text
End Sub



Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview