# Resize columns DesktopListbox

**URL:** <https://forum.xojo.com/t/resize-columns-desktoplistbox/76919>\
**Category:** General\
**Created:** [August 16, 2023, 12:04pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919 "2023-08-16T12:04:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [August 16, 2023, 12:04pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/1 "2023-08-16T12:04:53Z")

</div>

I used an “old” method to resize the columns in a ListBox. I tried to convert this existing method to Xojo Version 2023 release 1.1.

```auto
// Change Column Widths

Var p As New Picture(10,10)
Var g As graphics = p.Graphics

Var CellWidth as Integer
Var ColumnSize as Integer

g.FontName = Me.FontName
g.FontSize = Me.FontSize

for Column As Integer = 0 to Me.ColumnCount-1
  ColumnSize = g.TextWidth(Me.HeaderAt(Column))
  
  for Row As Integer = 0 to Me.LastRowIndex
    CellWidth = g.TextWidth(Me.CellTextAt(Row, Column))
    if CellWidth > ColumnSize then 
      ColumnSize = CellWidth
    End If
  next Row
  
  Me.ColumnAttributesAt(Column).WidthActual = ColumnSize + 20
next Column

```

No errors found… **But no resizing** … What is wrong with this code?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [August 16, 2023, 1:15pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/2 "2023-08-16T13:15:15Z")

</div>

> [@Carlos\_De\_Backer](#):
>
> ` Me.ColumnAttributesAt(Column).WidthActual = ColumnSize + 20`

This is the syntax:  
**ColumnAttributesAt** (column As [Integer](https://documentation.xojo.com/api/data_types/integer.html), [Assigns](https://documentation.xojo.com/api/code_execution/assigns.html) value As [DesktopListBoxColumn](https://documentation.xojo.com/api/user_interface/desktop/desktoplistboxcolumn.html))

does not looks the same (to me), but I may be wrong.

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [August 16, 2023, 1:20pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/3 "2023-08-16T13:20:12Z")

</div>

> [@Emile\_Schwarz](#):
>
> This is the syntax:  
> **ColumnAttributesAt** (column As [Integer](https://documentation.xojo.com/api/data_types/integer.html), [Assigns](https://documentation.xojo.com/api/code_execution/assigns.html) value As [DesktopListBoxColumn](https://documentation.xojo.com/api/user_interface/desktop/desktoplistboxcolumn.html))

The documentation here for desktoplistbox: [DesktopListBoxColumn — Xojo documentation](https://documentation.xojo.com/api/user_interface/desktop/desktoplistboxcolumn.html#desktoplistboxcolumn-widthactual)  
shows this example:

```auto
Me.ColumnAttributesAt(0).WidthActual = 80
Me.ColumnAttributesAt(1).WidthActual = 80
Me.ColumnAttributesAt(2).WidthActual = 45

```

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [August 16, 2023, 1:24pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/4 "2023-08-16T13:24:38Z")

</div>

> [@Carlos\_De\_Backer](#):
>
> No errors found… **But no resizing** … What is wrong with this code?

When you say “but no resizing”, what happens if you change:

```auto
Me.ColumnAttributesAt(Column).WidthActual = ColumnSize + 20

```

to (for example)

```auto
Me.ColumnAttributesAt(Column).WidthActual = ColumnSize + 100

```

do the columns change size or not?  
Can you check the value of ColumnSize before that line of code? You can put a break maybe ColumnSize = 0?

Can you provide a sample project?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [August 16, 2023, 1:38pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/5 "2023-08-16T13:38:50Z")

</div>

> [@AlbertoD](#):
>
> The documentation here for desktoplistbox

The examples are probably far below **ColumnAttributesAt** … because there are none there: ColumnAttributesAt

Bad online documentation.

Sorry for the error.

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [August 16, 2023, 2:15pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/6 "2023-08-16T14:15:44Z")

</div>

Sorry folks… My code is just perfect. The header of the DesktopListbox was not yet initialized before the method was started. This piece of code works well to resize a DesktopListbox based on het headers and data in the columns.

Thank you all!

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [August 16, 2023, 2:17pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/7 "2023-08-16T14:17:19Z")

</div>

The documentation is really bad… It takes a long time to find the correct methods, properties…

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [August 16, 2023, 2:22pm UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/8 "2023-08-16T14:22:13Z")

</div>

> [@Emile\_Schwarz](#):
>
> Bad online documentation

I usually use [https://docs.xojo.com](https://docs.xojo.com) but now that site is going away soon ☹

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [August 17, 2023, 8:20am UTC](https://forum.xojo.com/t/resize-columns-desktoplistbox/76919/9 "2023-08-17T08:20:31Z")

</div>

> [@AlbertoD](#):
>
> that site is going away soon

I do not found it so usefull: too near API2. Code taken from there does not compile in Xojo 2015…  
And when you have a MacBook Pro i5 / code with MacBook Pro m1…
