Combo-Box item location

ALX

Well-known member
Joined
Nov 16, 2005
Messages
249
Location
Columbia, SC
Programming Experience
10+
Is it possible to get the bounds / location of an item in a standard Combo-Box Drop down list?
 
Solution
The math is: Start with Point.Empty, adjust for width/height of combobox, adjust for ItemHeight * index. Use ComboBox.PointToScreen with that point.
But if you want to show drop down with some item selected just set SelectedIndex and then DroppedDown true.

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,558
Location
Norway
Programming Experience
10+
Yes, in DrawItem event when DrawMode is 'owner draw'. Why do you ask?
 

ALX

Well-known member
Joined
Nov 16, 2005
Messages
249
Location
Columbia, SC
Programming Experience
10+
I need to point to an item in a Combo Box drop-down list in one Form from a help page in another form. The drop down list is not owner draw although it could be changed. I figured the owner draw would give me the bounds within the drop down but not the location relative to the form or screen. I would need to do something like
VB.NET:
Rect1 = CB_DropDown.GetItemRectangle(7)
ReqPos = CB_DropDown.PointToScreen(New Point(Rect1.X + 30, Rect1.Y + 10))
which of course doesn't fly as Combo Box Drop Down does not support GetItemRectangle.
I also tried...

VB.NET:
Dim i As Integer = CB_DropDown.ItemHeight
ReqPos = CB_DropDown.PointToScreen(New Point(30, CB_DropDown.Height + CInt(i * 7)))

This gets close but it points to the wrong item in the drop down and it seems precarious to base it on the Height of the Combo Box itself . I'm hoping to find the accepted method.
I couldn't find anything through Google, Microsoft or Intellisense. I have done this many times with a standard ListBox but it appears Combo-Box Drop Downs are different...?
 
Last edited:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,558
Location
Norway
Programming Experience
10+
The math is: Start with Point.Empty, adjust for width/height of combobox, adjust for ItemHeight * index. Use ComboBox.PointToScreen with that point.
But if you want to show drop down with some item selected just set SelectedIndex and then DroppedDown true.
 
Solution

ALX

Well-known member
Joined
Nov 16, 2005
Messages
249
Location
Columbia, SC
Programming Experience
10+
Thanks John. That's what I figured. It just seemed tacky to me that there was not a method similar to GetItemRectangle for a Combo Box List. I was thinking that on another OS, theme or accessibility option, the list box might not be exactly where it is showing on my system in relation to the Combo Box.
 
Top Bottom