Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Want to delete the data using the ListView

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-01-2010
Member
 
Join Date: Aug 2006
Posts: 162
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
Reply With Quote
  #2  
Old 20-01-2010
Member
 
Join Date: Nov 2005
Posts: 1,323
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
If you select No after the confirmation asked, then the data will not get deleted. Clicking on Yes will delete the data. Hope that this code help you.
Reply With Quote
  #3  
Old 20-01-2010
Member
 
Join Date: May 2008
Posts: 2,389
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 :
  1. Right-click the project, click Add ASP.NET Folder, and then click App_Data, if the Web site does not have an App_Data folder, in Solution Explorer.
  2. Then right-click the App_Data folder in the Solution Explorer, and then click Add Existing Item. After doing this the Add Existing Item dialog box will be displayed.
  3. Then enter the location of the AdventureWorks database file (AdventureWorks_Data.mdf) was installed. The path "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf" is the default path where the .mdf file is installed.
  4. Then Open or Switch to the Default.aspx file.
  5. Later Switch to Design view.
  6. From the Data tab of the Toolbox, drag a ListView control onto the page.
  7. In the Common ListView Tasks menu, in the Choose Data Source drop-down list, click <New data source…>.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 20-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,521
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
If your problem is not solved you can post the error.
Reply With Quote
  #5  
Old 20-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,852
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 :
  • Where you can specify the data that you want to retrieve from the database, the Configure Data Source wizard is displayed.
  • Select the Specify a custom SQL statement or stored procedure option. Then follow the instructions given on the screen.
  • Enter the SQL query to retrieve department data from the Works database in the Define Custom Statements or Stored Procedures page.
  • Then click on the tab to do the according things. Like Click the INSERT tab and then enter the following SQL query to insert department data in the Works database.
  • Click the UPDATE tab and then enter the following SQL query to update department data in the Works database.
  • Click the DELETE tab and then enter the following SQL query to delete department data from the Works database.
  • Click Test Query to make sure that you are retrieving the data that you want.
  • Lastly click on the Finish.
The wizard creates a SqlDataSource control and adds it to the page. The ListView control that you added earlier is bound to the SqlDataSource control.
Reply With Quote
  #6  
Old 20-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,393
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.
Reply With Quote
  #7  
Old 20-01-2010
softtrickseo
 
Posts: n/a
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);


}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Want to delete the data using the ListView"
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


All times are GMT +5.5. The time now is 12:17 AM.