如何獲取DataGridView單元格值寫入C#中的MessageBox?如何獲取MessageBox中的DataGridView單元格值?
回答
您可以使用DataGridViewCell.Value屬性檢索存儲在特定單元格中的值。
所以檢索「第一」選擇小區和值顯示在MessageBox中,您可以:
MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString());
可能上面是不是正是你需要做什麼。如果您提供更多詳情,我們可以提供更好的幫助。
MessageBox.Show(" Value at 0,0" + DataGridView1.Rows[0].Cells[0].Value);
感謝!偉大工程! :) – Brezhnews 2011-04-06 19:45:03
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(Convert.ToString(dataGridView1.CurrentCell.Value));
}
有點遲,但希望它有助於
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}
try
{
for (int rows = 0; rows < dataGridView1.Rows.Count; rows++)
{
for (int col = 0; col < dataGridView1.Rows[rows].Cells.Count; col++)
{
s1 = dataGridView1.Rows[0].Cells[0].Value.ToString();
label20.Text = s1;
}
}
}
catch (Exception ex)
{
MessageBox.Show("try again"+ex);
}
我加入這一個DataGrid的按鈕來獲得該行的用戶點擊該單元格的值:
string DGCell = dataGridView1.Rows[e.RowIndex].Cells[X].Value.ToString();
其中X是要檢查的單元格。在我的情況下,Datagrid列計數從1開始,而不是0。不知道它是數據網格的默認值,還是因爲我使用SQL來填充信息。
總和所有細胞
double X=0;
if (datagrid.Rows.Count-1 > 0)
{
for(int i = 0; i < datagrid.Rows.Count-1; i++)
{
for(int j = 0; j < datagrid.Rows.Count-1; j++)
{
X+=Convert.ToDouble(datagrid.Rows[i].Cells[j].Value.ToString());
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
DataGridViewRow row = dataGridView1.Rows[rowIndex];
MessageBox.Show(row.Cells[rowIndex].Value.ToString());
}
Hi @سعدالضبي你可以在這個代碼塊中添加一些評論嗎? – 2017-11-27 10:22:07
代碼只有答案對社區沒有用處 – JimHawkins 2017-11-27 11:09:13
- 1. 如何獲取DataGridView單元格值?
- 2. 如何獲取datagridview中單元格的圖像值?
- 3. 如何獲取選定單元格的值DataGridView C#?
- 4. 根據網格座標在DataGridView中獲取單元格值
- 5. 如何獲取control.MouseDown上的DataGridView中單元格的位置?
- 6. C#--DataGridView - 無法獲取ColumnCount,無法獲取單元格值
- 7. 在datagridview中獲取單元格的2個值
- 8. dataGridView中的新autoNumber單元格獲取值-1,-2 ... etc
- 9. 返回在vb.net中獲取datagridview單元格的值
- 10. 如何獲取BandedGridView單元格的值
- 11. 如何從單元格單擊中的datagridview單元格中刪除值?
- 12. 單擊單元格時如何獲取單元格值?
- 13. 如何獲取DataGridView單元格內的按鈕的實例?
- 14. WinForms DataGridView單元格編輯結束事件獲取單元格
- 15. 如何在sqlserver中的單個單元格中獲取多個單元格值
- 16. 如何從gridview獲取單元格值?
- 17. 如何在datagridview的最後一行獲取一些單元格?
- 18. 獲取DataGridView複選框的單元格值?
- 19. 獲取DataGridView嵌套單元格的值For循環
- 20. DataGridView單元格值遞增
- 21. datagridview行單元格值
- 22. 如何驗證DataGridView中的單元格?
- 23. 如何更新datagridview中的單元格?
- 24. 在DataGridView中更改單元格的值
- 25. 更改DataGridView中的單元格值
- 26. 如果DataGridView的單元格值大於另一個單元格
- 27. 如何使用jQuery獲取html表格中的單元格值
- 28. 獲取單元格值
- 29. 獲取QTableView單元格值
- 30. DataGridComboboxColumn - 獲取單元格值
謝謝!但它足夠了,你告訴我,解決了我的問題:) – Brezhnews 2011-04-06 19:54:23
MessageBox.Show(dataGridView1.SelectedCells [0] .Value?.ToString()); – Xarylem 2017-10-16 15:44:54