ListBox.ActiveTextControl Alignment

I mentioned before that I thought one could set the alignment property in ActiveTextControl - but now I can’t get it to work.

When pressed, the listbox aligns the text to the left, despite the activeTextControl.alignment set to right.

Screenshot 2022-07-12 at 12.09.10

Using this code in the cellPressed event.

Me.CellTypeAt(row,column) = desktoplistbox.CellTypes.TextField
Me.ActiveTextControl.TextAlignment = TextAlignments.Right
Me.cellTextAt(row, column) = s  //the string value
Me.EditCellAt(row, column)

I would like the text in the TextField to be aligned horizontally and vertically on demand, obviously neither is happening.

One way:

  • store each number as a double in the cellTag (the example below has 1 column and uses RowTag)…

  • in the listbox.PaintCellText event use something similar to the sample below to draw whatever you want in the cell, exactly where you want. You can have the text drawn and aligned, in colour, highlighted, add little icons if you wish, etc. It even works for hierarchical listboxes, noting that the x-coordinate is shifted right for each level.

Note you must return true from the listbox.PaintCellText handler for it to take effect.

Result:

Thanks Nicholas. The problem is not with the paint event - I have similar code in there already, but as I tried to illustrate with the image it is EditCell which is the problem - this is where the activeTextControl should work with its formatting - but it always seems left and top aligned.

I haven’t looked at this in a while, but I have a vague recollection of this not working unless I set the properties later using a Timer.CallLater. I don’t have the time or ability currently to check, but that’s what I’m thinking.

Yes, I have some old coding that would imply that this was the way to do it, but I can’t seem to make it work anymore.

It seems that quite a few of the formatting functions are not working

  • alignments
  • text selection
  • underline
  • have created a Feedback Issue here: xojoinc/xojo#69304

Having worked a little more on this I thought I’d document my workaround to get cell alignments (and other things) in the to replace the editCellAt function - essentially a grow your own editCell.

In the cellPressed event I embed a containerControl in the container underlying the listbox. The containerControl includes a textField (or datetimepicker or other items).

The position and size of the containerControl is determined by the columnNo, columnwidths and HeaderHeight, rowHeight of the listbox (using % or * variables in the widths would complicate this a bit).

Alignment, fonts, font sizes are also passed to the containerControl depending on the alignment required.

On loss of focus of the textField, its value raises a changed event to pass the value back to the original listbox cell.

The images show the result which is pretty close to the desired result.

Right Align


Left Align

Numbers

Dates

This technique would essentially allow any type of information to be presented and edited within standard listbox.

1 Like

I was going to suggest using AddControl, but hadn’t gotten back around to this yet. Glad you found a solution you’re happy with.

I split the recent discussion in to a new topic as the original thread was about something different.

Then my post no longer makes sense :wink: