I have a datagridview. i want to select some cells which spreaded in different columns and rows. when i hit Delete key this cells should be clear. i could achieve this for cells of text type as follows (I use MS Access as the database and all fields are numbers)
if (e.KeyData == Keys.Delete)
{
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
string i = "";
cell.Value = (object)i;
}
this really clear all deleted cells. but what shall i do if the cells are numbers . how i can assign null value to these numbers while deleting.
if (e.KeyData == Keys.Delete)
{
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
int i =0;
cell.Value = (object)i;
}
the above code make all deleted cell with zeros . I want to avoid that situation. I dont want to place a zero for null.
another approach I did is
if (e.KeyData == Keys.Delete)
{
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
cell.Value = cell.DefaultNewRowValue;
}
but this do not work when i select cells of more than one row . how i can solve it;
please somebody help please......