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~

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

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.Items.AddRange(lines)
           ListBox1.SelectedIndex = 0
        End Sub
Private Function lines() As String
  Throw New NotImplementedException
End Function

Edited 1 Year Ago by arivbot

Using LINQ you can just do:

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

You'll need:

Imports System.Linq

Edited 1 Year Ago by pritaeas

This article has been dead for over six months. Start a new discussion instead.