Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Deleting data using a listview


  • Please log in to reply

#1
Simondo

Simondo

    Member

  • Member
  • PipPipPip
  • 113 posts
Hey

I'm fairly new to VB and I'm stuck!
I've worked out how to retrieve and imput data into a table and updating it on a listview using a form, but I cant work out how to delete it from the tables using a delete button whilst having the row selected in the listview.

Any help would be greately appreciated!

I'm using Visual Studios 2005. VB.net!
(I think thats all you need lol)

Cheers

Simon

Edited by Simondo, 09 February 2009 - 07:57 AM.

  • 0

Advertisements


#2
Sockdown

Sockdown

    Member

  • Member
  • PipPipPip
  • 393 posts

Hey

I'm fairly new to VB and I'm stuck!
I've worked out how to retrieve and imput data into a table and updating it on a listview using a form, but I cant work out how to delete it from the tables using a delete button whilst having the row selected in the listview.

Any help would be greately appreciated!

I'm using Visual Studios 2005. VB.net!
(I think thats all you need lol)

Cheers

Simon


Hello Simondo,

What exactly do you want to delete? An item or the whole list?
  • 0

#3
Simondo

Simondo

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 113 posts
Hey

Firstly thanks for your reply.

I'm looking to permanatly delete 1 row of data. I would also like to include a msgbox yes/no in there somewhere.

Cheers =)
  • 0

#4
Sockdown

Sockdown

    Member

  • Member
  • PipPipPip
  • 393 posts
It might not be the best way, since we are entering a loop for only one item(if you select no to multiple select), but if you decide to allow multi select, then it works too.
Sub BtnDeleteClick(sender As Object, e As EventArgs)
	Dim selItem As New ListViewItem
	Dim result As DialogResult
		
	result = MessageBox.Show("Are you sure you want to delete the selected item(s)?", _
								 "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		
	If result = DialogResult.No Then
		MessageBox.Show("Delete action has been cancelled.", "Delete Cancelled", _
			MessageBoxButtons.OK, MessageBoxIcon.Information)
	Else
		For Each selItem In listViewRec.SelectedItems
			selItem.Remove()
		Next
	End If
End Sub

Hope this helps you.
-Sockdown-

Edited by Sockdown, 11 February 2009 - 12:59 PM.

  • 0

#5
Simondo

Simondo

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 113 posts
Heya

Sorry for the late reply.

That does help and it does seem to work. However when I refresh the screen using another button the data reappears. Thinking about it, it was probably me wording it wrong in the original question.

I need to not only remove the data from the listview, but also permanatly from the SQLTable.

Thanks a bunch!

Cheers

Simondo
  • 0

#6
Sockdown

Sockdown

    Member

  • Member
  • PipPipPip
  • 393 posts
Ohhhhh, that's another thing hehe. That needs a query to the database to delete. lol. Well, what database are you using? SQL Server? Oracle? MySQL?
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP