Results 1 to 5 of 5

Thread: Deleting a row from a Data Table using a DGV - only works once

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2012
    Posts
    20

    Question Deleting a row from a Data Table using a DGV - only works once

    I have a data table that is connected to a data grid view. I want to delete the selected row from the data gird view. It works for the first time I delete a row, but when I select another row and try to delete it the program crashes as I get an "Index Out of Row exception". "There is no row at position X"

    Your help would be great!

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim selectedi As Integer = dgvCustomers.CurrentCell.RowIndex
    
            dtdgvCustomers.Rows(selectedi).Delete()
            Me.Validate()
            Me.objCustomersDA.Update(Me.objDataSet.Tables("tblCustomers"))
            Me.objDataSet.AcceptChanges()
            Refresh()
            dgvCustomers.Update()
    
    
            dgvCustomers.ClearSelection()
    
        End Sub
    
    
    Public Sub Retrieve()
            'Clears DataSet of any existing data
            objDataSet.Clear()
            
    
            objCustomersDA.FillSchema(objDataSet, SchemaType.Source)
            'Fills DataSet with info from DataAdapter
            objCustomersDA.Fill(objDataSet)
    
            'objDataSet.Tables.Add(dtCustomers)
    
    
            dgvCustomers.DataSource = objDataSet.Tables(0)
    
       
    
        End Sub
    Last edited by NewToThis101; Mar 17th, 2013 at 02:41 PM. Reason: spelling

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width