find begin and end of column position

Dim row,column As Integer row = Me.RowFromXY(System.MouseX - Me.Left - Self.Left - me.Parent.Left, System.MouseY - Me.Top - Self.Top - Me.Parent.Top) column = Me.ColumnFromXY(System.MouseX - Me.Left - Me.Parent.Left - me.TrueWindow.Left, System.MouseY - Me.Top - Me.Parent.Top - Me.TrueWindow.Top) MsgBox("You clicked in cell " + Str(row) + ", " + Str(column))

Is there a way to find the column’s current width and begin x/y and end x/y?

I am trying to determine an action based on where in a specific column is clicked.

Thank you,
Robb

http://documentation.xojo.com/index.php/ListBox.Column
http://documentation.xojo.com/index.php/ListColumn

[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 !)

1 Like

[quote=340525:@Norman Palardy]http://documentation.xojo.com/index.php/ListBox.Column
http://documentation.xojo.com/index.php/ListColumn[/quote]

Thanks Norman. Is there a way to get the starting and ending position of the column?

Robb

[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.

Thank you,
Robb

You might be able to use the cellcick event, it gives you x,y relalive to the left/top of the cell clicked.

Or you could do something like this?

dim c1left,c2left,c3left as Integer c1left = 0 c2left = Listbox1.Column(0).WidthActual c3left = c2left + Listbox1.Column(1).WidthActual

[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=340546:@Neil Burkholder]You might be able to use the cellcick event, it gives you x,y relalive to the left/top of the cell clicked.

Or you could do something like this?

dim c1left,c2left,c3left as Integer c1left = 0 c2left = Listbox1.Column(0).WidthActual c3left = c2left + Listbox1.Column(1).WidthActual[/quote]

Thanks for helping me think outside of my box :slight_smile:

for i = 0 to maxcol
c1left = c1left + Listbox1.Column(i).WidthActual
next i

This worked great for what I needed.
Robb

No Problem. You could even subclass the listbox and add ColLeft and ColRight properties.

[code]Dim lb as Listbox = Listbox1

Dim ColLeft(),ColRight(),pos As Integer

For i As Integer = 0 To lb.ColumnCount-1
ColLeft.Append pos
pos = pos + lb.Column(i).WidthActual
ColRight.Append pos
Next

For i As Integer = 0 To lb.ColumnCount-1
lb.cell(0,i) = ColLeft(i).ToText + "; "+ ColRight(i).ToText
Next
[/code]

[quote=340548:@Norman Palardy]starting point - Add up all the widths of the columns that came before
ending point - starting point + actual width[/quote]

And what if the listbox is scrolled horizontally?

Did you try the provided Code / Clues / Advices ?

Why ?

Because you add the actual column widths, and never use Listbox.Width or Listbox.Left or… in Neil code above (IMHO).

ListBox1.ScrollPositionX

Emile,

[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.

You’re likely to get better / more useful replies if you try something and post “Hey this is what I tried and it didn’t work. Why not?”