1 Replies - 5515 Views - Last Post: 06 November 2006 - 08:08 PM Rate Topic: -----

#1 bsm1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-November 06

Editing data held in listview, by taking info from multiple text boxes

Posted 06 November 2006 - 06:51 AM

Hi there, wonder if anyone can help, i am trying to take data that has already been inputed into a listview box and then edit this informaiton, i have a seprate form that pops up when the button edit it clicked, however i just cant seem to work out how to take this edited informaiton and replace it with what should now appear, have got the inforamtion to add ok but can anyone help with editing. Thanks please respond uregently, thanks

P.S i am using visualbasic.net 2003

Code for this form as below
Private Sub bttnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnadd.Click
		' this sub takes the informaiton that the user has inputed into frmaddedit and adds it to the listview under its approprate heading in  the form display screen
		If Me.Text = "Add" Then
		
			dispscreen.spylist.Items.Add(fstnam.Text)
			Dim i As Integer = 0
			i = dispscreen.spylist.Items.Count - 1
			dispscreen.spylist.Items.Item(i).SubItems.Add(surnam.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
			dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

			Me.Hide()
		Else
			' this part of the sub takes information that has been inputed into edit screen when the edit button has been clicked and replaces it by what was previously selected
			If Me.Text = "Edit" Then
			 [b] this is where the error is showing [/b] 
 'dispscreen.spylist.Items(dispscreen.spylist.SelectedIndices.Item(0))
				Dim i As Integer = 0

				i = dispscreen.spylist.Items.Count - 1
				dispscreen.spylist.SelectedItems.Item(i).SubItems.Add(fstnam.Text)
				dispscreen.spylist.SelectedItems.Item(i).SubItems.add(surnam.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
				dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

				Me.Hide()
			End If
		End If
		'this part of the sub sets the input screen back to a blank value it basically clears the formadd back to a blank state ready for the next set of details to be added
		fstnam.Text = ""
		surnam.Text = ""
		age1.Text = ""
		cdenam.Text = ""
		specskil.Text = ""
		sex.Text = ""
		distinmar.Text = ""
		swbank.Text = ""
	End Sub

	Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
		' this sub handels the button cancel in the form addedit, this button closes the input screen (frmaddedit) and takes the user back to the main display screen
		Me.Close()
	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Editing data held in listview, by taking info from multiple text boxes

#2 psykoprogrammer  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 09-October 06

Re: Editing data held in listview, by taking info from multiple text boxes

Posted 06 November 2006 - 08:08 PM

Items in a listbox in .NET are an array of objects (allowing generic items to be inserted). You can generally reference the exact item index and replace the value with whatever you choose, if I'm remembering correctly.

For Index = 0 To listBox.Items.Count - 1
   listBox.Items[Index] = "Item #" + Index.ToString();
Next



Forgive my VB. I never use it. I use C#. Either way, that should get you close. Cheers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1