Based on the design requirements, the datagridview can not be edited directly by the user. It is in read-only mode. When the user double-clicks on the cell, the datagridview's read-only property becomes false and the cell accepts keyboard input. However, the raw keyboard input needs to be formatted before it goes in the cell. So, I intercept the KeyPress events as follows:
private void dgw_keyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
At this point the cell is in edited mode and dirty mode. Then I update the Value property in a different method and call dgw.Refresh()
which is supposed to display the updated value on the cell. But it won't. it will update only when the current cell is not dirty and is not in edit mode. How can I force the cell display the updated value while it is still in edit mode?
Any ideas?
Use below to refresh the current cell's value, change to suit your EditingControl type
if (dgvMain.EditingControl is TextBox)
{
dgvMain.EditingControl.Text = dgvMain.CurrentCell.Value.ToString();
}
Another method:
Call this method to force a cell to update its display value in edit mode. This is useful when an external process modifies the cell value and you want to notify the user of the change, even when a user-specified change is lost as a result.details
dgvMain.RefreshEdit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With