I have a strange issue when adding items to a listbox. I want it to adjust it’s size to match it’s count. When adding 1 all is fine, add the second and the rows go to 4 then after we have more than 4 all is working fine. The other thing is the location of the top of the listbox also moves up a few pixels – wierd. Is this a bug? This is the button event code for adding them. Updated!
Dim s As String = tbTest.Text
If Not s = "" Then
Dim li As New ListItem(s)
If Not lsbTest.Items.Contains(li) Then
lsbTest.Items.Add(li)
Dim i As Integer = lsbTest.Items.Count
lsbTest.Rows = i
lsbTest.Height = i * 22
End If
End If
Don’t use Rows property. Let it stretch by setting the CSS height to 100% of a containing div.
UPDATE:
Take a look at this solution (Googled it):
Allowing listbox to grow vertically….