in the DataGridView I want the cell size to expand according to the string length when I edit the cell. Excel does the same.
In the DataGridView, w
This was work for me:
Enable KeyPreview
Property of the form and change the body of KeyPress
Event of the form to this:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar!='\b') //discard backspace
{
dataGridView1.Columns[0].Width += 5; //the column's index or name
}
else
{
dataGridView1.Columns[0].Width -= 5; //for backspase pressing
}
}
you can limit the pressed keys with e.KeyChar
;