[code]Public Function MouseAfterColumn(extends alb as Listbox, x as Integer, y as Integer) as Integer
’ returns the column number of the given mouse clic in the header of the Listbox
dim i,awidth as Integer
dim res as Integer = -1
dim acolumn as Integer = alb.ColumnCount
if y<=alb.HeaderHeight then
if acolumn>0 then
awidth=0
for i=0 to acolumn-1
awidth =awidth + alb.Column(i).WidthActual
if x>awidth-3 and x<awidth+3 then
res = i
exit For
end if
next
end if
end if
Return res
End Function
[/code]
Edit: not tested on a retina display (I don’t have one !)
[quote=340529:@Jean-Yves Pochez][code]Public Function MouseAfterColumn(extends alb as Listbox, x as Integer, y as Integer) as Integer
’ returns the column number of the given mouse clic in the header of the Listbox
dim i,awidth as Integer
dim res as Integer = -1
dim acolumn as Integer = alb.ColumnCount
if y<=alb.HeaderHeight then
if acolumn>0 then
awidth=0
for i=0 to acolumn-1
awidth =awidth + alb.Column(i).WidthActual
if x>awidth-3 and x<awidth+3 then
res = i
exit For
end if
next
end if
end if
Return res
End Function
[/code]
Edit: not tested on a retina display (I don’t have one !)[/quote]
How do I use this method. I am getting an error that says the method extends class Listbox, but the base expression is class . How do I fix this? I put the method into a module.
[quote=340539:@Robert Kantor]Thanks Norman. Is there a way to get the starting and ending position of the column?
[/quote]
starting point - Add up all the widths of the columns that came before
ending point - starting point + actual width
[quote=340541:@Robert Kantor]How do I use this method. I am getting an error that says the method extends class Listbox, but the base expression is class . How do I fix this? I put the method into a module.
Thank you,
Robb[/quote]
columnNumber = mylistbox.MouseAfterColumn( mylistbox.mousex, mylistbox.mousey)
should do it.
[quote=340548:@Norman Palardy]starting point - Add up all the widths of the columns that came before
ending point - starting point + actual width[/quote]
[quote=340611:@Emile Schwarz]Did you try the provided Code / Clues / Advices ?
Why ?[/quote]
No, I didn’t try it because I could tell from a quick skim that it made the assumption the listbox was visible from the first column. I was pressed for time so I just was pointing out that, as coded, it would not necessarily give you the expected result. Even if it seemed to on tests where there was no horizontal scrollbar.
As Neil pointed out later, it can be accounted for using ScrollPositionX, but that was not done in any of the proposed solutions.