Delete selected row from datagridview and update DB?

Private void btnDelete_Click(object sender, EventArgs e) { foreach (var item in this. DataGridView1. SelectedRows) { dataGridView1.Rows.

RemoveAt(item. Index); } }.

There is no . Index option... – Woody Jan 18 '10 at 8:03 use 'DataGridViewRow' instead of var. – Navid Farhadi Jan 19 '10 at 13:17.

Pls, see id this code would work for you foreach (DataGridViewRow row in dataGridView1. SelectedRows) if (!row. IsNewRow) dataGridView1.Rows.

Remove(row); using index of the selected row still could work; see if the code below would do the trick: int selectedCount = dataGridView1.SelectedRows. Count; while (selectedCount > 0) { if (!dataGridView1. SelectedRows0.

IsNewRow) dataGridView1.Rows. RemoveAt(dataGridView1. SelectedRows0.

Index); selectedCount--; } hope this helps, regards.

Thanks... the main problem I'm having now is saving to the database using tableadapters. – Woody Jan 20 '10 at 4:02 you need to provide more details on what is not working for you; I bet the best response you would get by starting a new question with a code snip which is causing troubles – serge_gubenko Jan 20 '10 at 4:35.

Here is one very simple example: ASPX: Code Behind: public partial class _Default : System.Web.UI. Page { private readonly DataTable _dataTable; public _Default() { _dataTable = new DataTable(); _dataTable.Columns. Add("Serial", typeof (int)); _dataTable.Columns.

Add("Data", typeof (string)); for (var I = 0; ++i SelectedIndex Cells collection, but for this simple case //we will use index of selected row in database. _dataTable.Rows. RemoveAt(i); //rebind with data BindData(); //clear selection from grid gvTest.

SelectedIndex = -1; } } you will have to use checkboxes or some other mechanism to allow users to select multiple rows and then you can browse the rows for ones with the checkbox checked and then remove those rows.

I'm using WinForms... – Woody Jan 18 '10 at 19:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions