[英]Windows Forms: Datagridview cell value not updated when it is modified
我正在修改Datagridview單元中的值,但未在單元中更新該值。 我已經嘗試過dataGridView.Refresh(),dataGridView.RefreshEdit()和dataGridView.EndEdit(),但是它們都不起作用。 我究竟做錯了什么?
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView.Columns[browseDataGridViewButtonColumnName].Index)
{
var dialogResult = openFileDialog.ShowDialog();
if (dialogResult != DialogResult.OK)
{
return;
}
var fileNameAndPath = openFileDialog.FileName;
dataGridView[e.RowIndex, FileNameAndPathColumnIndex].Value = fileNameAndPath;
}
}
更改最后一行
dataGridView[e.RowIndex, FileNameAndPathColumnIndex].Value = fileNameAndPath;
使用Cells
dataGridView[e.RowIndex].Cells[e.ColumnIndex].Value = fileNameAndPath;
您可以使用以下解決方案來解決您的問題:
this.dataGridView1.RefreshEdit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.