How to hide the blank rows in listbox

Hi,

Assuming that I have a listbox on the full window, but the retrieved data from database are just 2 rows.
In that case, I see 20 rows and 18 rows are blank.

I can’t expect how many rows will be retrieved in advance. Only know it will be less than 20.
I just want to see 2 rows and don’t want to see the 18 of blank rows.

Can you tell me how I can do that?

listbox.height=listbox.listcount*listbox.rowheight

assuming rowheight is NOT (-1), otherwise set it to a real value

This would be rather non-standard UI though, no? What about changing the background color of the inactive cells to grey or something like that?

That’s what I do, and is the standard behavior for some of the VB6 grids I cut my teeth on. In the CellBackgroundPaint event:

If row < Me.ListCount Then
  ' normal cell drawing here 

Else ' below last active row, fill in with gray
  g.ForeColor = &c888888
  g.FillRect(0, 0, g.width, g.height)

End If

Hiding method works well.

Thank you so much.

One more thing.

In case I use below code, the ‘Dotted’ lines are not removed.

Open event

Me.List.GridLinesHorizontal = me.List.BorderThinDotted

Try BorderThinSolid. Just pull up the Help file and experiment with it some, the ListBox is pretty flexible.