none
what is vb.net code for delete a record in datagrid using vb.net windows application?

Answers

  • Hi,we can delete the datatable row ,then it will be reflected on the datagrid.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            Try

                ds.Tables(0).Rows.RemoveAt(Me.DataGrid1.CurrentRowIndex)

                da.Update(ds)

                MessageBox.Show("success!")

            Catch ex As Exception

                MessageBox.Show("fail")

            End Try

          

        End Sub

     

    Hope it helps

    Regards.

    Friday, May 18, 2007 7:29 AM

All replies

  • Code Snippet

    Private Sub cmdRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRemove.Click

    With Me.dgvMain

    For Each r As DataGridViewRow In .SelectedRows

    .Rows.RemoveAt(r.Index)

    Next

    End With

    End Sub

     

    Sunday, May 13, 2007 6:36 AM
  • hai element109

                    can't delete any record from datagrid using ur code,i am very new to vb.net windows so plz help...

    regards

    sathyanarayanan

     

    Sunday, May 13, 2007 7:30 AM
  • I'm sorry I did not realize you were using a System.Windows.Forms.DataGrid, my code uses the newer control System.Windows.Forms.DataGridView which is based on the DataGrid control. You can change to the newer control by finding your DataGrid declaration in YourFile.Designer.vb change the declaration to DataGridView.
    Sunday, May 13, 2007 7:57 AM
  • Are you using VB Express or an earlier version of VB.NET.    If you are using VB Express its highly likely your using a datagridview control.   If so, are you using databinding ? (did you set the datasource property).

     

    Do you want to delete the row from the grid but next time the grid is loaded want the data to re-appear or do you want to remove the data permanently from the database.

     

    Monday, May 14, 2007 4:22 PM
  • Hi Sathyanarayanan,

       Move the thread from Visual Basic Express Edition in order to get better answers.

       Thanks for your understanding!

    Thursday, May 17, 2007 8:39 AM
  • Hi,we can delete the datatable row ,then it will be reflected on the datagrid.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            Try

                ds.Tables(0).Rows.RemoveAt(Me.DataGrid1.CurrentRowIndex)

                da.Update(ds)

                MessageBox.Show("success!")

            Catch ex As Exception

                MessageBox.Show("fail")

            End Try

          

        End Sub

     

    Hope it helps

    Regards.

    Friday, May 18, 2007 7:29 AM
  • Hi !

    I  am Sujay .I need to your help.In this code error message in vs2005. "(Me.DataGrid1.CurrentRowIndex)" .Please help me.

    I want to delete and update datagrid value.

    Please help me.

    Thanks.


    Try

                ds.Tables(0).Rows.RemoveAt(Me.DataGrid1.CurrentRowIndex)

                da.Update(ds)

                MessageBox.Show("success!")

            Catch ex As Exception

                MessageBox.Show("fail")

            End Try

          

    Monday, August 27, 2007 10:45 AM