Question ListBox counts item and pass to textbox

vincent15mark

Member
Joined
Sep 12, 2010
Messages
5
Programming Experience
Beginner
sd.JPG

How can I count the number of items in my listbox.
here is my codes:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myListbox.Items.Add(txtText.Text & "")
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtTextListCount.Text = myListbox.Items.Count
End Sub

please help me guys..
thank you
 
This works for me....
VB.NET:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.ListBox1.Items.Add(Me.TextBox1.Text)

        Me.txtTextListCount.Text = Me.ListBox1.Items.Count.ToString

End Sub
 
View attachment 2570
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myListbox.Items.Add(txtText.Text & "")
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtTextListCount.Text = myListbox.Items.Count
End Sub

The problem is that you have the code to display the count
txtTextListCount.Text = myListbox.Items.Count
in the wrong event, put it under the Button1_Click event, or under a separate button event
 
Back
Top