# ListBox.ActiveTextControl Alignment

**URL:** <https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192>\
**Category:** General\
**Created:** [July 12, 2022, 5:13pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192 "2022-07-12T17:13:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Pitchford](https://forum.xojo.com/user_avatar/forum.xojo.com/james_pitchford/32/4568_2.png) [@James\_Pitchford](https://forum.xojo.com/u/James_Pitchford)\
**Post date:** [July 12, 2022, 5:13pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/1 "2022-07-12T17:13:11Z")

</div>

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](https://forum.xojo.com/uploads/default/original/2X/f/f31dff356da9aa47b8ef0caf73adeb8765318457.png)

Using this code in the cellPressed event.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Loveday](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@Nicholas\_Loveday](https://forum.xojo.com/u/Nicholas_Loveday)\
**Post date:** [July 13, 2022, 12:59pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/2 "2022-07-13T12:59:42Z")

</div>

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.

 ![Screen Shot 2022-07-13 at 11.02.38 pm](https://forum.xojo.com/uploads/default/original/2X/3/3d3ef9159ea73ab96382db74e3f164c7febb579e.png)

Result:

 ![Screen Shot 2022-07-13 at 11.01.42 pm](https://forum.xojo.com/uploads/default/original/2X/2/27d46dc9801992355eb66e3405190486f7fbc53c.png)

---

<div class="post-metadata">

**Author:** ![James\_Pitchford](https://forum.xojo.com/user_avatar/forum.xojo.com/james_pitchford/32/4568_2.png) [@James\_Pitchford](https://forum.xojo.com/u/James_Pitchford)\
**Post date:** [July 13, 2022, 1:38pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/3 "2022-07-13T13:38:43Z")

</div>

> [@Nicholas\_Loveday](#):
>
> listbox.PaintCellText

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.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [July 13, 2022, 1:47pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/4 "2022-07-13T13:47:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![James\_Pitchford](https://forum.xojo.com/user_avatar/forum.xojo.com/james_pitchford/32/4568_2.png) [@James\_Pitchford](https://forum.xojo.com/u/James_Pitchford)\
**Post date:** [July 13, 2022, 4:43pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/5 "2022-07-13T16:43:27Z")

</div>

> [@Anthony\_G\_Cyphers](#):
>
> Timer.CallLater

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.

---

<div class="post-metadata">

**Author:** ![James\_Pitchford](https://forum.xojo.com/user_avatar/forum.xojo.com/james_pitchford/32/4568_2.png) [@James\_Pitchford](https://forum.xojo.com/u/James_Pitchford)\
**Post date:** [July 13, 2022, 7:11pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/6 "2022-07-13T19:11:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James\_Pitchford](https://forum.xojo.com/user_avatar/forum.xojo.com/james_pitchford/32/4568_2.png) [@James\_Pitchford](https://forum.xojo.com/u/James_Pitchford)\
**Post date:** [July 14, 2022, 7:51pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/7 "2022-07-14T19:51:11Z")

</div>

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

 ![Screenshot 2022-07-14 at 14.46.43](https://forum.xojo.com/uploads/default/original/2X/f/fbe745dd8898039e6b3c02f9e981523cc559c515.png)  
Left Align  
 ![Screenshot 2022-07-14 at 14.46.50](https://forum.xojo.com/uploads/default/original/2X/9/91e1d55d57a3bb7afc8d162c2b2f0b4d07c0473d.png)  
Numbers  
 ![Screenshot 2022-07-14 at 14.46.57](https://forum.xojo.com/uploads/default/original/2X/a/aacb9b399da0d7873f4132c5693d8f4f98ea4b82.png)  
Dates  
 ![Screenshot 2022-07-14 at 14.47.03](https://forum.xojo.com/uploads/default/original/2X/2/241f3c75468acd7e1cf3b33a5a9a785a0e40cff3.png)

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

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [July 14, 2022, 8:03pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/8 "2022-07-14T20:03:21Z")

</div>

I was going to suggest using [AddControl](https://blog.xojo.com/2022/01/21/simplified-adding-user-interface-controls-at-runtime/), but hadn’t gotten back around to this yet. Glad you found a solution you’re happy with.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [July 15, 2022, 8:17am UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/10 "2022-07-15T08:17:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [July 15, 2022, 12:34pm UTC](https://forum.xojo.com/t/listbox-activetextcontrol-alignment/71192/11 "2022-07-15T12:34:03Z")

</div>

Then my post no longer makes sense 😉
