DesktopListbox column size with static size

Hello,

I am trying to adjust size of columns in a listbox trying to mix % and fixed widths

I would like to use the second mode when the user resize the columns, other columns are moved and not resized doc

I have the following code, what I want is that the right most column always keep the same size but if the user enlarge the windows, the column 4 stick to the rightmost part

me.ColumnCount = 5
me.AllowResizableColumns = True
me.ColumnAttributesAt(0).WidthExpression = "20%"
me.ColumnAttributesAt(1).WidthExpression = "20%"
me.ColumnAttributesAt(2).WidthExpression = "20%"
me.ColumnAttributesAt(3).WidthExpression = "20%"
me.ColumnAttributesAt(4).WidthExpression = "100"
me.ColumnAttributesAt(4).MaxWidthExpression = "100"
me.ColumnAttributesAt(4).MinWidthExpression = "100"

There is a gap on the right when I make the window bigger.

But if I set a column width to “*” or empty, I switch to mode 1 and other columns are shrinked when I make a column bigger.

How can I achieve what I am trying to do?
Do I have to calculate percentage in the resized event based on the width of the listbox?

Thank you

Since the first 4 Columns have equal widths, why not just do a:

Me.ColumnCount = 5
Me.AllowResizableColumns = True
Me.ColumnWidths = "*,*,*,*,100"

Since Xojo calculates the widths from left to right, I suspect that it calculates 4 x 20% correctly, but then has more than 100 pixels for column 5 and then limits this to 100 without expanding the first 4 columns again.

Of course it would be better for Xojo to subtract 100 from the total width of the list and then calculate the percentage widths… :slight_smile:

I would say this is worth a bug report.

I am not doing multiple * because sometimes I want to give ratio. From the documentation we can say 4*, 3*, * but it results in the first mode when increasing/decreasing the size of a column use the space of an other column

In the example I gave, it’s 20% but in fact, I am using something more like different percentages (40%,10%,25%, etc)

I do not know if this is a bug or not

I’m also not sure.

A Quck&Dirty Workaround for your Issue, may be something like this in a Resizing/Resized Event:

Var theWidth As Integer = ListBox1.Width - 100

ListBox1.ColumnAttributesAt(0).WidthExpression = Str(theWidth * 0.40)
ListBox1.ColumnAttributesAt(1).WidthExpression = Str(theWidth * 0.10)
ListBox1.ColumnAttributesAt(2).WidthExpression = Str(theWidth * 0.15)
ListBox1.ColumnAttributesAt(3).WidthExpression = Str(theWidth * 0.35)

ListBox1.ColumnAttributesAt(4).WidthExpression = "100"
ListBox1.ColumnAttributesAt(4).MaxWidthExpression = "100"
ListBox1.ColumnAttributesAt(4).MinWidthExpression = "100"
1 Like

even better, in BackgroundPaint event

I suspect that would be triggered far too often.

1 Like

if there is no change in value - nothing happens.