listbox height in steps

Hello,

if i resize a window i want to resize the height of my listbox too, this is easy done with the lock feature.
But the listbox should show additionally rows only if there is is enough space for a complete row(height), not only a part of it.

i tried with “Listbox.Height mod Listbox.RowHeight” to get the remaining height but i am stuck.

any suggestions?

Thanks Marco

Can you post your code?

i’ve got it working with a “helping”-Control, a rectangle control which is the same height as the listbox…

in window resizing event

dim h as integer = Rectangle1.Height mod Listbox1.RowHeight if h > 0 then Listbox1.Height= Rectangle1.height - h end if

it works as expected but maybe there is a way without the helping-control?

What happens to the text height displayed in the height reduced Rows ?

Marco, you can use the window height to do some calculations, that way you don’t need Rectangle1

Emile, I think Marco wants to always show complete rows, the default behavior is that the Listbox can show the last row a little bit/half.

Big thanks Alberto!

i’ ve got in the open-event:

a=window1.Height-(Listbox1.top+Listbox1.height)

and in the resizing-event:

dim h as integer = (window1.Height-a) mod Listbox1.RowHeight if h >= 0 then Listbox1.Height= (window1.Height-a) - h end if

and this works without the helping-rectangle…

How did your code look like?

The Row Height does not change.

@Emile Schwarz
why should the row height change? its just to display a “whole” row…

I misread your question yesterday; i recall I found that strange, but people sometimes ask what appears strange questions and often have good reason to ask.

Now that I think at your question - a genuine question - I do not / never asked it in my mind: I let the user to decide the window (thus the Listbox) height.

What I have done recently is to resize the Window Height to display - when possible - the whole Listbox contents (when a DataBase file have only a few number of Records to display), because I had enough to reside down the window in a Multi-Data Base List View displayer window. I used that method to do that (+ 1 empty line to be sure the last line is correctly displayed).

[quote=410347:@Marco Winster]Big thanks Alberto!

How did your code look like?[/quote]
No problem, I like to find answers to questions, that way I learn.

The code looks much like yours. I think you have a little bug:

  • a for you is only the distance between Listbox1 “bottom” and Window1 “bottom” and not the difference in Height

Listbox1 Open event:

a = Self.Height - Me.Height For i As Integer = 0 To 25 Me.AddRow ("A row just for testing") Next i

Window1 Resizing:

If CheckBox1.Value Then Dim h As Integer = (Self.Height - a) Mod Listbox1.RowHeight If h > 0 Then Listbox1.Height= (Self.height -a) - h End If End If

  • the checkbox test is for demo purposes, this way I was able to activate/deactivate the option

Have you considered putting the code in Resized event instead of Resizing, that way it only ‘fix’ your Listbox how you wanted when the user let go resizing the window. If you do, you have to put Invalidate at the top of the Resized event if you are using mac so the windows contents are cleared before redrawing the listbox.

As a user this behavior would annoy me. But each to his or her own.

I agree. Dont do this.