Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I unselect the selected item if the user clicks an area that has no items?

0
Posted

How can I unselect the selected item if the user clicks an area that has no items?

0

The ItemFromPoint property retrieves the index of the item from the cursor. The ColumnFromPoint property gets the index of the column’s header from the cursor. The following sample unselect the last selected item, if the user clicks a section of the control that has no items: Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As Long, c As Long Dim b As Boolean b = True With List1 i = .ItemFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY, c) If (i < 0) Then If (.HeaderVisible) Then c = .ColumnFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY) b = c < 0 End If If (b) Then With .Items If (.SelectCount > 0) Then .SelectItem(.SelectedItem(0)) = False End If End With End If End If End With End Sub The ShowFocusRect property hides the thin rectangle around the focused item. The FocusItem property of Items object gets the index of the focused item.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123