简体   繁体   中英

Change value of selected cell from datagridview to zero (0)

I have connection to an Excel file which displays in datagridview. I would like to change value of selected cell ind datagridview to "0" (zero) by clicking a button.

在此处输入图片说明 As you can see from pic, there is a button "Null cell" and selected one cell. Any ideas?

Try to use the code below. If you will select several cells than the button sets the value to zero only for the first cell.

private void button1_Click(object sender, EventArgs e)
{
    var selected = dataGridView1.SelectedCells[0];
    dataGridView1.Rows[selected.RowIndex].Cells[selected.ColumnIndex].Value = 0;
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM