Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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