Editing a cell in a listbox - text position

Hi, apologies if this has already been covered elsewhere, I did search but couldn’t find anything.

Is there a way to control the appearance of the TextField that appears when you click on an editable cell in a listbox? e.g. centre the text vertically so its inline with the rest of the row?

See attached pic, looks a bit rubbish on a Mac (not tried on other platforms).

Thanks,
Dave.

File a bug report using Feedback.

Don’t hold your breath 'till the bug wll be removed…

Hi Emile, thanks for replying, but I’ve worked around it.

In the listbox’s CellClick event:

me.EditCell row, Column

if row = 0 Then
  me.ActiveTextControl.Top = me.ActiveTextControl.Top+1
  me.ActiveTextControl.Height = me.RowHeight-6
  
Else 
  me.ActiveTextControl.Top = me.ActiveTextControl.Top+4
  me.ActiveTextControl.Height = me.RowHeight-6
  
End

me.ActiveTextControl.AllowFocusRing = false

… gives a far better user experience:

Regards,Dave.

4 Likes

This code takes care of variable Listbox.DefaultRowHeight > -1:

Me.EditCellAt(row, column)

Static dTextHeight As Double

If dTextHeight = 0 Then
  
  Var p As New Picture(1, 1)
  Var g As Graphics = p.Graphics
  
  g.FontName = Me.FontName
  g.FontSize = Me.FontSize
  
  dTextHeight = g.TextHeight
  
End If

Me.ActiveTextControl.Height = dTextHeight
Me.ActiveTextControl.Top = Me.ActiveTextControl.Top + (Me.RowHeight / 2) - (Me.ActiveTextControl.Height / 2)

4 Likes

Thank you for the code.

strangely, this workaround code does not do anything in my listbox. What could be the reason for that? Is there a minimum version of Xojo for this? (mine is 2019 r3,1)

It‘s API 2.0 code. Maybe that’s the reason?

I tried to find out more on API 2.0. I might blame myself here, but how do I install API 2.0? Somehow in the documentation it looks to me as this would be included in 2019r2?

2019r2 and all new versions since…

Can’t you use something newer than 2019r3,1 ?

Read the release notes to know what was changed since that version…

What trouble have you with the shared code ?

Thanks Emile, but shouldn’t 2019r3 be a later version than 2019r2, hence it should include API 2.0?

Yes, but there were many changes between both versions, and some reverted changes.

So, what trouble did you have ? At compile time is something rejected ? (an error is reported on the code ?)

I am with a m1 computer now (and here), and I cannot check older versions, only 2021r2.1 is installed here.

Where did you placed the code ?

There is no error. It is just the formatting issue as in the image in the top post. The text jumps up, when cell is activated.

in the listbox cellclick event as David Yeaman suggested.

I read too fast (did not noticed that bit of info).

I checked in an old project; placed the code as is and it works fine. I removed the code… and the “bug” does not appears.

This is with Xojo 2021r2.1.

I checked the Release Notes and found not that change…

So maybe it is time for me to upgrade once more… thanks Emile for checking.