hi
I want to delete rows in my gridview whit button delete on keyboard.what do I do?
hi
I want to delete rows in my gridview whit button delete on keyboard.what do I do?
try this
add a delegate to your gridView like this in the form.designer.cs file. Find the area where your gridview properties are being set and add this line at the bottom of the section.
this.gridview.KeyDown += new System.Windows.Forms.KeyEventHandler(gridview_KeyDown);
Then in your event handler do the following
void gridview_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
//checks to see if the delete button has been clicked and if there are selected rows
if (ModifierKeys == Keys.Delete && gridview.SelectedRows.Count > 0)
{
//perform delete
}
}
I write this code and delete my selected row .
private void GridviewName_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
var delete = from del in Movie_List.Requests
where del.Movie_Name == GridviewName.Rows[GridviewName.CurrentCell.RowIndex].Cells["ColumnName"].Value.ToString()
select del;
foreach (var Item in delete)
{
Movie_List.Requests.DeleteOnSubmit(Item);
Movie_List.SubmitChanges();
}
}
Good Luck