Simple Question Listbox..

frankwhite

Well-known member
Joined
Nov 30, 2004
Messages
49
Programming Experience
Beginner
Hi, Is there a way I can list the number of items in a Listbox in a Text box, for example if there are 6 items in a listbox, i want to show '6' in the textbox, or if there are no items then '0' is shown in the textbox I know its an embarassing question, but if someone could help id appreciate it.

Thanks
 
Thanks for that.

Sorry to divert this question from the main thread, but if i dont have items in Listbox2 how can i select the first item in listbox1?

I have the following so far but it doesnt work on the Selecteditem line for some reason:

If Listbox2.Items.Count = 0 Then
ListBox1.SelectedItem
End If :confused:
 
Im sorry when i tried that its just not working, its just got 0 in there.

is your listbox called listbox1? if so

VB.NET:
Textbox[COLOR=Red][B]1[/B][/COLOR].Text = ListBox[COLOR=Red][B]1[/B][/COLOR].Items.Count.Tostring
-------

Thanks for that.

Sorry to divert this question from the main thread, but if i dont have items in Listbox2 how can i select the first item in listbox1?

I have the following so far but it doesnt work on the Selecteditem line for some reason:

If Listbox2.Items.Count = 0 Then
ListBox1.SelectedItem
End If :confused:
VB.NET:
  If Listbox2.Items.Count = 0 Then
              ListBox1.SelectedIndex = 0
          End If
 
I don't know what to tell you... I built a little app with 2 listboxes, and ran my code I posted earlier and it ran fine??? Are you getting any error messages?
 
Its in the form load event, Im not sure y it is not working. However something might help you the two listboxes are different. The first listbox is reading data from a database and the second one is just a string, im not sure if that is the problem.
 
I just dont know, the following is on the same page and it doesnt work:

TextBox2.Text = lstItems.Items.Count.ToString

However, on another page I have:

TextBox1.Text = frmmain.lstItems.Items.Count.ToString

and the above works :confused:
 
Back
Top