Datagridview cell value is not updated when dynamically changed

According to the design requirements, datagridview cannot be edited directly by the user. It is in read-only mode. When a user double-clicks on a cell, the datagridview property to read becomes false, and the cell accepts keyboard input. However, the original keyboard input must be formatted before it enters the cell. So, I intercept KeyPress events as follows:

private void dgw_keyPress(object sender, KeyPressEventArgs e)
 {
     e.Handled = true;
 }

At this point, the cell is in edit mode and dirty mode. Then I update the Value property in another method and call dgw.Refresh()which should display the updated value in the cell. But this is not so. it will be updated only when the current cell is not dirty and is not in edit mode. How can I make a cell display an updated value while it is still in edit mode?

Any ideas?

+5
source share
4 answers

Use below to update the current cell value, change it according to the EditingControl type

if (dgvMain.EditingControl is TextBox)
{
    dgvMain.EditingControl.Text = dgvMain.CurrentCell.Value.ToString();
}

Another method:

, . , , .

dgvMain.RefreshEdit();
+11
0

I decided using the code below.

GrdBudgetTabOver.EndEdit()
0
source

All Articles