Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combobox: How to detect the hihghlighted Item?
Message
 
To
24/12/2006 20:35:14
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01179918
Message ID:
01180109
Views:
18
>>that means it's either in the valid or interactivechange - and not a true tooltip.

HI Dragan,

I've found a similar problem described in some delphi forum and an idea to solve it.

The idea is: to start a timer every time the combobox gets focus or on MouseEnter and to disable it on lostfocus or when the mouse is neither in the combobox nor in the rectangle of the list.

Then every e.g. 100 ms the timer checks the position of the cursor and calculates the index of the item that should be under the cursor.

Quick and dirty:
FUNCTION Timer
	LOCAL loComboBox as ComboBox, lnMouseCOl, ;
              lnComboTop, lnDistanceFromCombo, lnHighlitedIndex

	lnHighlightedIndex = -1
	loComboBox = This.oComboBox
	
	lnComboTop = loComboBox.Top
	lnMouseCol = MROW(0,3)
	
	lnDistanceFromCombo = lnMouseCol - lnComboTop - loComboBox.Height
	
	If lnDistanceFromCombo < loComboBox.ListCount * This.nItemHeight 
             lnhighlightedIndex = Int(lnDistanceFromCombo / This.nItemHeight)
        ENDIF
    
        IF lnHighlightedIndex < 0
    	     lnHighlightedIndex = .Null.
        ENDIF
    
    IF .not. ISNULL(lnHighlightedIndex)
	    WAIT "Highlighted Item ist "+STR(lnHighlightedIndex) WINDOW nowait
    EndIf
    
    RETURN lnHighlitedIndex
EndFunc    	
Yes, it must be also proved, if the X-Position of the mouse ist still in the rectangle, but the biggest disappointment, that makes it all unusable is the fact, that the first item seen in the list is not the first item defined there. The list is always shown beginning with the item that has been last selected. And so the approach from above does not (and cannot!) take in account, that there are probably some more items, that are not visible and stand in the list virtually above the combobox. That's it...
Alexander Lerner
a_lerner@heinrich-schmid.de

The life is somewhat easier than it seems to be.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform