|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Want to delete the data using the ListView
I am fairly new to the Visual Basic and I am stuck in a problem. I am not able to delete the data using the ListView. When I tried coding for that it is not working and I am not getting the desired output. I am made code that retrieves and inputs data into a table. Even I can update the data using the form on a ListView. But I am not getting the proper coding for deleting the data from the table using the delete button whilst having the row selected in the ListView. I am using the Visual Studio 2005. Hope that somebody can help me soon.!!
__________________ Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991 |
#2
| |||
| |||
Re: Want to delete the data using the ListView
Here is the code for deleting the data from the ListView. Using this code you can delete the whole row of the data. I have also included message box in the coding so that it will ask for the confirmation. Here is the code for deletion of data : Code: 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 ![]() |
#3
| |||
| |||
Re: Want to delete the data using the ListView
If you want to display and modify the data in the ListView control, you can follow the steps given below :
__________________ The FIFA Manager 2009 PC Game |
#4
| |||
| |||
Re: Want to delete the data using the ListView
I think that this code will work : Code: Private Sub Command3_Click() 'If con.State = adStateOpen Then Dim con As ADODB.Connection Set con = New ADODB.Connection con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb") Set rs = New ADODB.Recordset Dim x As Integer If Not con Is Nothing Then 'added check to see if con is set to a valid object For x = ListView1.ListItems.Count To 1 Step -1 If ListView1.ListItems(x).Checked = True Then con.Execute "DELETE from Supplier where Supplier_Name='" & ListView1.ListItems(x).SubItems(1) & "'" ListView1.ListItems.Remove x End If Next con.Close Set con = Nothing Else MsgBox "Connection not set" End If End Sub |
#5
| |||
| |||
Re: Want to delete the data using the ListView
If you are using the SQL as your database, then after following the steps mentioned by the 'opaper' you will have to follow these steps :
|
#6
| |||
| |||
Re: Want to delete the data using the ListView
According to me the code mentioned by the 'absolute55' should work. I have not tried it for myself, but looking at the code I can guess that it should work. The only thing is that, if you are using the SQL and you try to delete the row using the coding then you can only delete the data from the ListView, but that data will remain in the SQLTable. If you want to delete the data from the SQLTable also then you will have to make changes in that coding.
__________________ Grand Theft Auto 4 PC Video Game |
#7
| |||
| |||
Re: Want to delete the data using the ListView
Just Put commandname of your Linkbutton and write below code in ItemCommand event of ListView protected void ListViewJobs_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName.Equals("DeleteJob")) { ListViewDataItem currentItem = (ListViewDataItem)e.Item; Guid jobid = new Guid(ListViewJobs.DataKeys[currentItem.DisplayIndex].Value.ToString()); JobController obj = new JobController(); new JobController().CancelJob(jobid); } } |
![]() |
|
Tags: asp net, delete, form data, listview, sql query, sqltable, visual basic, visual studio 2005 |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to use Vscrollbars with Listview | Suffix | Software Development | 1 | 01-10-2011 11:46 AM |
Transfer the data to another listview | Chhaya | Software Development | 3 | 05-10-2009 12:19 PM |
ListView or ListBox | Heather5 | Software Development | 3 | 29-08-2009 12:10 AM |
limits on listview | Christopher | Software Development | 3 | 17-10-2008 03:07 PM |
Will reinstalling WIN XP delete my data ? | Ihit | Windows XP Support | 4 | 25-01-2005 04:14 AM |