Listbox column sizing

How can i size a Listbox Column to the length of the Listbox.Heading of this Column?

A simple:

Listbox1.Column(0).WidthActual = Len(Listbox1.Heading(0))

does not work.

I’m not sure I understand it correctly: you say, you have a heading that is wider (or narrower) than its column. I don’t think this is even possible with the Xojo listbox.

No, i have a listbox with 22 columns. i want each column be as (min)-width as its Heading.

What I meant is: a heading and its column always have the same width.

sure. i know. i want to to size the column so that the Heading is always displayed completely. Let say you have a heading “This is a damned large heading”, then i want to size the whole column to the size of this heading.

Got me?

Oh, you mean to the text length of the heading?

yes. the whole text in the heading should be readable.

Maybe something like that:

Dim p As New Picture(1, 1) p.Graphics.TextFont = Me.TextFont p.Graphics.TextSize = Me.TextSize Me.Column(0).WidthActual = p.Graphics.StringWidth(" " + Me.Heading(0) + " ")

something like that?

Example

Yes, Axel. Works like Elis solution as well. Thank you both.

But that brings me to the next problem. The horizontal scrollbar is not showing up, but it is activated in the control-inspector.

The horizontal scrollbar only shows, when the width of all columns is greater than the listbox width. If you want the scrollbar always visible, set AutoHideScrollBars to False.

Hmm… the width of all 21 columns is much larger than the listbox. but there is no scrollbar. the columns to the right are just cut off.

Have you switched on Horizontal Scrollbar in the inspector ?

yes. i can see it in the IDE, but when i run the app within the IDE, the horizontal scrollbar is not displayed.

Open Axel’s example
Change ColumnCount to 20
Set ScrollbarHorizontal to True
Run the application

–> the horizontal scrollbar is shown (with Xojo 2015.1 on OS X)

That right. Now i just have to find out, whats the difference between Axel’s Listbox and mine.

there should be no difference, i have dropped a listbox to the window.

To get the horizontal scroolbar in the Xojo native ListBox, you have to have the ColumnWidths be Pixels values, not % nor *.

I have hard time to understand that and Dave S. had also hard time to let me understand it (that was something I could not believe, for some unknow reason).

Get an eye on Resizing Columns, first paragraph. Where they talk about ListBox modes (first and second) and every column width is specified as an absolute amount

Thank you. I will try this.

I do this in the listbox Open-Event:

  Listbox1.Heading(0) = App.k_Customernumber
  Listbox1.Heading(1) = App.k_Firstname
  Listbox1.Heading(2) = App.k_Lastname
  Listbox1.Heading(3) = App.k_Street
  Listbox1.Heading(4) = App.k_Streetnumber
  Listbox1.Heading(5) = App.k_Postcode
  Listbox1.Heading(6) = App.k_City
  Listbox1.Heading(7) = App.k_Telephone
  Listbox1.Heading(8) = App.k_Telefax
  Listbox1.Heading(9) = App.k_Email
  Listbox1.Heading(10) = k_DateOfBirth
  Listbox1.Heading(11) = k_Inventorynumber
  Listbox1.Heading(12) = k_Accountholder
  Listbox1.Heading(13) = k_Bankname
  Listbox1.Heading(14) = k_BankLocation
  Listbox1.Heading(15) = k_IBAN
  Listbox1.Heading(16) = k_SwiftCode
  Listbox1.Heading(17) = k_Tariff
  Listbox1.Heading(18) = k_CurrentProvider
  Listbox1.Heading(19) = k_CurrentProviderCustomernumber
  Listbox1.Heading(20) = k_LastYearConsumption
  Listbox1.Heading(21) = k_Signature
  
  for i as Integer = 0 to 21
    Listbox1.Column(i).WidthActual = 100
  next

So every column has a size of 100. looks good. i can only see lets say 8 columns when using the startrup-width of the window, the rest is cut of on the right side. The ScrollbarHorizontal is set to Yes in the Inspector, but still no horizontal Scrollbar is displayed.