I am looking for the most efficient way to read the last line of listbox in visual basic
For example, if my listbox contains the following:
a
b
c
d
e
f
g
Then the output whenever I clicked the button should be the last line
which is g
I am using this code to get the job done, however I am looking for the most effiicient and effective way for this when I have thousands or even hundred thousands of item in listbox.
Dim lastline As Integer = (lstData.Items.Count - 1)
lstData.Text = lstData.Items(lastline).ToString
events_class.events_function(lastline)
答案 0 :(得分:0)
This will get a total number of contents in your list box.
'This code will set the selected index of the item to the last item in
'the list, regardless of how many items are in it.
If ListBox1.Items.Count > 0 Then _
ListBox1.SelectedIndex = ListBox.Items.Count - 1
Hope this will help you.. Regards