In Windows Forms DataGridView, How Can I Delete the values of selected cells through drag?
Multiselect is applied as true in datagridview But I don't know how to delete dragged cells.
private void DataGridView1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Delete:
if (dataGridView1.Focused == true)
{
dataGridView1.CurrentCell.Value = "";
dataGridView1.EndEdit();
//MultiSelect Cell Delete All Cells(Drag)
}
else if (dataGridView2.Focused == true)
{
dataGridView2.CurrentCell.Value = "";
dataGridView2.EndEdit();
}
break;
case Keys.Back:
if (dataGridView1.Focused == true)
{
dataGridView1.CurrentCell.Value = "";
dataGridView1.EndEdit();
}
else if (dataGridView2.Focused == true)
{
dataGridView2.CurrentCell.Value = "";
dataGridView2.EndEdit();
}
break;
}
}
Try using DataGridView.SelectedCells
property to gets the collection of cells selected by the user.
DataGridView.CurrentCell
gets only the currently active cell.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.