Hello!
I have a dataGridView1. I have added one row with the string: "This is a string".
Now what I try to do is to change the string by typing something new like: "This is a string2"
What I try to do is that the string MUST change in the cell.Value after each KeyUp event, which means Instantly after each new letter is pressed while writing in the textBox cell.
However the _KeyUp event is putting the original "This is a string" value back each _KeyUp event.
How can we achieve this functionality?
Thank you!
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add(); int index = dataGridView1.Rows.Count - 2;
dataGridView1.Rows[index].Cells[0].Value = "This is a string";
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewTextBoxEditingControl tb)
{
tb.KeyUp -= dataGridView1_KeyUp;
tb.KeyUp += dataGridView1_KeyUp;
}
}
//then in the keyup event handler, execute your code
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (dataGridView1.EditingControl is TextBox)
{
//Trying to change the cell.Value to current text in the cell. But it sets back the orignal string in the CELL ?
dataGridView1.EditingControl.Text = dataGridView1.CurrentCell.Value.ToString();
}
}