Example. I have 12 lines in my TXT. When I Upload it into listbox. The listbox force the lines tobe 10 lines.
Anyone can teach me how to limit lines on listbox.
Any help would be greatly appreciate. Thank you~

4
Contributors
6
Replies
15
Views
2 Years
Discussion Span
Last Post by pritaeas

A listbox can hold any number of lines. If you mean that it limits the number of visible lines, you can change that by changing the Height property. If you do

ListBox1.Height = ListBox1.ItemHeight * (1 + ListBox1.Items.Count)


then, assuming the form is big enough, the listbox will display all items without requiring a scrollbar.

Thankyou for your post, but I mean when I have 12 lines in my TXT. When I Upload it into listbox. The listbox force the lines tobe 10 lines, so the listbox will be delete the 11 and 12 line

Please post your code. A snapshot of the textbox would also help.

Maybe the lines in your textbox are wrapped? Make your listbox wider and see if you have all the txt there.

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If String.IsNullOrEmpty("D:\email1.txt") Then
Exit Sub
End If
Dim lines() As String = IO.File.ReadAllLines("D:\email1.txt")
ListBox1.SelectedIndex = 0
End Sub
Private Function lines() As String
Throw New NotImplementedException
End Function


Edited by arivbot

Using LINQ you can just do:

ListBox1.Items.AddRange(lines.Take(10))


You'll need:

Imports System.Linq


Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.