Delete a Selected row

I am trying to delete a row in DataGridView with a Button from a ToolBar. I have written code to add a row with input from the user and need to find out how to delete a certain rwo that I click on and highlight. Is this possible If yes how would I go about telling the delete command which row is to be deleted Thanks. Nick


Answer this question

Delete a Selected row

  • DiamonDogX

    DataGridView1.Rows.Remove(DataGridView1.CurrentRow)

    will remove the current row.

    To remove a specific row (e.g. row 3) you can use

    DataGridView1.Rows.RemoveAt(3)


  • Cactus77

    I thought we were talking about datagridviews. What is Me.DevicesDataSet.Workstations
  • Liebethal

    If you are binding the DataGridView to a binding source, I would recommend you call BindingSource.Remove(BindingSource.Current) instead of directly calling the remove method on the DataGridView. The binding source will synchronize the current values with the DataGridView based on the change of the BindingSource. Similarly, I recommend using the BindingSource.AddNew method for adding a row in the DataGridView from external buttons.

    Jim Wooley
    http://devauthority.com/blogs/jwooley



  • afrc2

    Here is what I have so far for the button. CuurentRow does not seem to work. Anymore suggestions

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click

    Me.DevicesDataSet.Workstations.Rows.Remove(i need to know what goes in here)

    End Sub

    End Class



  • Delete a Selected row