Listbox and Window Size

Hi,

I’m not sure this is the place, but I have a problem. I’m writing a code for structural analysis, and I need to set the Height of a ListBox. I’m using Lisbox.Height and until there so far so good, did the job. But I need to resize the Window too, and the change of Window’s size affects the Lisbox size, adding more rows that should. I tried the “locking” combinations, tried to fix the lisbox coordenate with Listbox.Top, change the order of the code, resing window first and after listbox, but all without success. It seems that I can’t change the Window size without mess the listbox.

Sorry for bad english, I’m Brazilian :smiley:

you cannot use the locks AND manipulate the size manually… is this what you are trying to do?

The locks will force the listbox to follow the changes in the windows size…
locking the top/left will normally keep that corner in the same place, while the bottom/left will control the size

if you want to display only “X” rows, regardless of the windows size, then DO NOT lock the bottom, then you control the HEIGHT yourself, and let Xojo control the “WIDTH”

Hi Dave,

Running the code step by step, I noticed that one parameter called “ListCount” starts with “4” of value. On the help page, this property stands for the number of rows of the listbox. When I change de textfield that controls the amount of rows, for instance, defining 5 rows, I set the height for 20+20*5 because I set the default height at 20. And them I add 5 rows with ListBox.Addrow, because I need to change some cells in the process. By doing this, the code applies correctly the size, showing just the 5 rows, but still is possible to Wheel down in the listbox and see others rows that I didn’t add. Looking step by step, I noticed that the listbox already starts with 4 rows.
This time I didn’t change the Window size, now I think that was not the problem. By the way, I could not change this ListCount Property.

ListCount is read only.

Why don’t you tell us your end goal and we’ll try to help you get there.

I just need a listbox with X rows. To do that, I was thinking on changing the listbox size to fit X rows, changingthe Window size to fit the listbox and adding X rows, so I can edit the cells.

You’ll need to use a bit of math in that case. With X being the number of rows that you want to display and a RowHeight value set in the Listbox properties (replacing the default of “-1”):

theListBox.Height = (theListBox.RowHeight * X)

I changed the DefautRowHeight to “20”, then I used this simply equation that you wrote. But with X = 5, the total amount of rows was 9.
LB_Minfo.Height=20+20*val(TF_Nelem.Text)
for i as integer = 0 to val(TF_Nelem.Text)-1
LB_Minfo.Addrow
LB_Minfo.Cell(i,0)=cstr(i+1)
next

TF_Nelem is the TextField that controls the amount of rows decided by user. I set at least 20 so the listbox doesn’t disappear
As I told before, after this, I can scroll down and see others rows.

are you saying TOTAL rows is 9, or TOTAL VISIBLE rows is 9?

What Tim said will limit the VISIBLE rows, if you don’t want more rows “available”, its up to YOU to add/remove them

The total of rows is 9, I saw that debug, on the listbox, in the line “Contents”. Without add any row, it already has 4 rows. I tried remove these and got OutOfBoundsExecption on the third. So, I can’t create a listbox with just one row

you misunderstand how a listbox works…

there are TWO components…

  1. how many rows of DATA do you have (ie… addrow )
  2. how many rows COULD it show (based on rowheight and listbox height)

If you have an EMPTY listbox, with a rowheight of 20 and a listbox height of 100… it will SHOW 5 blank rows. But you cannot delete them because there is NO DATA.
If you add one line of data, if will show that data and 4 blank rows, until such time as you exceed the 5 VISIBLE rows, then the scrollbar appears. You will still never SEE more than 5 rows, but you can scroll to the rest

So VISIBLE rows is LISTBOX_HEIGHT/ROW_HEIGHT (regardless of how many rows have data)

Thank you for the explanation, now I can think correctly how to do what I need.

Much appreciated for all the help!