簡體   English   中英

如何刪除DataGridView中的當前單元格?

[英]How to delete the current cell in DataGridView?

如何刪除 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="";
        }
    }
}

以下鏈接描述了如何實現您想要的,
請檢查鏈接,我相信這會對您有所幫助,

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

我不知道你為什么要刪除 CellValidating Event 中的單元格值..

要刪除 CurrentCell 中的值 .. 你可以嘗試

DataGridView1.CurrentCell.Value = ""

我不確定 %100,但您可以使用DataGridView.CurrentCell屬性,例如;

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

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM