[英]How do I get the cell value from a datagridview using row index and column index in c#?
[英]Get cell value using row index and column index c#
我試圖通過在DataGridview中選擇一個單元格/行,然后單擊“刪除”按鈕來通過其ID刪除用戶。 我試圖通過使用行索引和列索引來獲取ID。 但是,即使我的datagridview包含行,我也無法刪除用戶,因為'string id'的值為NULL。
private void buttonDeleteUser_Click(object sender, EventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;
int columnindex = 0;
string id = dataGridView1[rowindex, columnindex].Value.ToString();
controller_employee.delete_employee(Int32.Parse(id));
}
為什么它為NULL,我該怎么辦?
ID = dataGridView.SelectedCells[0].RowIndex;
在此處,SelectedCells [0]指定列號。
並嘗試選擇整行而不是單個單元格
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.