0

如何删除 DataGridView 中的当前单元格。我正在尝试下面的代码,但它正在删除除当前单元格之外的所有单元格。

private void dgvPurchase_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    for (int i = 0; i < datagridview.Columns.Count; i++)
    {
        for (int j = 0; j < datagridview.Rows.Count; j++)
        {
            datagridview.Rows[j].Cells[i].Value="";
        }
    }
}
4

4 回答 4

1

以下链接描述了如何实现您想要
的,请检查链接,我相信这会对您有所帮助,

http://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx

于 2013-07-03T14:29:36.890 回答
1

我不知道您为什么要在 CellValidating Event 中删除单元格值..

要删除 CurrentCell 中的值 .. 您可以尝试

DataGridView1.CurrentCell.Value = ""
于 2013-07-03T15:05:46.113 回答
0

我不确定 %100 但您可以使用DataGridView.CurrentCell类似的属性;

int yourcolumnIndex = datagridview.CurrentCell.ColumnIndex;
int yourrowIndex = datagridview.CurrentCell.RowIndex;

datagridview.Rows[yourrowIndex ].Cells[yourcolumnIndex].Value="";

甚至使用DataGrid.CurrentCellChanged事件可能是更好的方法。

于 2013-07-03T14:28:34.477 回答
0

DataGridName.Rows.RemoveAt(DataGridName.CurrentCell.RowIndex);

于 2020-12-12T06:55:13.310 回答