Windows窗体:Datagridview单元格值在修改时未更新

问题描述:

我正在修改Datagridview单元格中的值,但未在单元格中更新gettting。我已经尝试dataGridView.Refresh(),dataGridView.RefreshEdit()和dataGridView.EndEdit()但他们都没有工作。我究竟做错了什么?Windows窗体:Datagridview单元格值在修改时未更新

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; 

    } 
} 
+1

@ARUNEdathadan,它的WinForm的,因此没有必要调用的'的DataBind()' – Rahul

改变你的最后一行

dataGridView[e.RowIndex, FileNameAndPathColumnIndex].Value = fileNameAndPath; 

要使用Cells

dataGridView[e.RowIndex].Cells[e.ColumnIndex].Value = fileNameAndPath; 
+0

我通过改变固定它最后一行dataGridView [FileNameAndPathColumnIndex,e.RowIndex] .Value = fileNameAndPath;愚蠢的错误。 –