Real Software Forums
http://forums.realsoftware.com/

Fixed width ListBox columns
http://forums.realsoftware.com/viewtopic.php?f=7&t=47014
Page 1 of 1

Author:  cm_rb [ Thu Feb 21, 2013 11:19 am ]
Post subject:  Fixed width ListBox columns

Hello,
I load data from a SQL-Database into a ListBox. Because I do not know in advance how many columns the ListBox will need to have, I put some code in the open event of the ListBox. The code tells how many columns the listbox (lb) should have and sets the width of the columns to 200 pixels.

Code example for a 10 column ListBox:

lb.ColumnCount = 10
dim i as Integer
for i = 0 to 9
lb.column(i).MinWidthActual = 200
lb.column(i).WidthActual = 200
next


Problem 1: After running then project, the horizontal scrollbar does not appear despite the fact, that the listbox content is much wider then the listbox. „ScrollBarHorizontal“ is checked in the IDE.

Problem 2: The above code behaves diferrently if I check/uncheck „AutoHideScrollbars“ for the listbox in the IDE and run the project. If „AutoHideScrollbars“ is checked, the column widths are not set to 200 pixels when I run the project.

Problem 3: When I resize the window/listbox the columns widths always change. The listbox seems to try to fit all the columns into its current width.
To solve Problem 3, I put some code in the „Resized“ event of the window, to make the column withs again 200 pixels wide:

dim i as Integer
for i = 0 to 9
lb.column(i).WidthActual = 200
next

The code in the „Resized“ event resizes the columns but leads to slow redrawing.

What am I doing wrong? How do you programmaticaly give the columns a fixed (or minimum) width which persists even when the window/listbox is resized? How do I make the horizontal scrollbar appear?

Real Studio 2012 R 2.1, Mac OS X 10.6.8

Author:  cm_rb [ Thu Feb 21, 2013 12:07 pm ]
Post subject:  Re: Fixed width ListBox columns

I made a small example project for demonstration:

http://cmezes.com/lb_example.zip

Author:  DaveS [ Thu Feb 21, 2013 12:16 pm ]
Post subject:  Re: Fixed width ListBox columns

try putting LB.INVALIDATECELL(-1,-1) (check the LR for syntax.. .I *THINK* that is correct)

Author:  cm_rb [ Thu Feb 21, 2013 1:52 pm ]
Post subject:  Re: Fixed width ListBox columns

Hello Dave,
thanks for your reply. I tried the „InvalidateCell“ method but it made no difference.
After some trial and error I stumbled upon the fact, the if I use for example ...
lb.ColumnWidths = "200,200,200,200,200,200,200,200,200,200"

in the open event of the listbox, then everything seems to work correctly.
The solution I found seems to be, to assemble a string (according to the number of columns) that passes the column widths to lb.ColumnWidths.
Here is some example code that seems to solve all 3 problems I described and which I put in the open event of the listbox:


dim i, k as Integer
dim c as String

k = 10 // put any number (<64) here

lb.ColumnCount = k

for i = 0 to (k - 1)
if i < (k - 1) then
c = c + "200,"
else
c = c + "200"
end if
next

lb.ColumnWidths = c


Edit: It would be very interesting to know why the first approch behaves so differently.

Author:  doofus [ Thu Feb 21, 2013 8:22 pm ]
Post subject:  Re: Fixed width ListBox columns

I don't know why MinWidthActual doesn't work but WidthExpression seems to do the job...
Sub Action()

lb.ColumnCount = 10

for i As integer = 0 to lb.ColumnCount - 1
lb.Column(i).WidthExpression = "200"
next

End Sub

Author:  cm_rb [ Fri Feb 22, 2013 4:00 am ]
Post subject:  Re: Fixed width ListBox columns

Thanks,
lb.WidthExpression works as expected.
The „...Actual“ properties do work too, but apparently only afterwards, when the column widths were initially set in the open event of the listbox with „lb.ColumnWidths“ or „lb.WidthExpression“.
Maybe the Language Reference should be more clear how to use this properties.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/