2 Replies - 7370 Views - Last Post: 26 November 2009 - 11:20 AM Rate Topic: -----

#1 Essel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 118
  • Joined: 08-May 09

Moving through listbox items one by one with a loop

Posted 26 November 2009 - 09:25 AM

Please i have a listbox full of items and i want to use a loop to access these items one after the other and then process each one for admission.That is when the item is at memory location 0, it will work on that item and the move to the next at memory location 1 till it gets to the end of all the items in the list box but my loop is not working i have tried different types of techniques but none of them it working these are my codes
Dim i As Integer
		Dim count = Me.lstbprocessapplicant.SelectedItems.Count

		For i = 0 To count - 1
			SelectedApp = Me.lstbprocessapplicant.SelectedItems(i)
			Me.lstbprocessapplicant.Items.Item(i).ToString()
' this loop gave me and index out of range exception and i changed it to this 

			Me.lstbprocessapplicant.Items(i).ToString()
  Me.lstbprocessapplicant.Items.Item(i).ToString()
		   
'And this loop is also giving me another execption

me.lstbprocessapplicant.selectedindices.count
Me.lstbprocessapplicant.items.selectedindice(i)

'This one only gave me the indexes 



Please help me

Is This A Good Question/Topic? 0
  • +

Replies To: Moving through listbox items one by one with a loop

#2 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Moving through listbox items one by one with a loop

Posted 26 November 2009 - 10:15 AM

Hi

I had a quick play and tried this

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


		Dim myItem As Object
		For Each myItem In Lstbprocessapplicant.Items
			ListBox1.Items.Add(myItem.ToString)
		Next

	   
	End Sub


I added another listbox to test it. It reads through you listbox then adds the data to the new listbox. You can change the code to add the data to what ever you want
Was This Post Helpful? 1
  • +
  • -

#3 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Moving through listbox items one by one with a loop

Posted 26 November 2009 - 11:20 AM

Hi Essel

Thanks for the thanks and Im glad the code worked for you
:D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1