I have a DataGridView with 3 columns. I need the first two columns remain constant, These columns always have to be the same and the user will not be able to enter a different value to these.
The values for the two first columns of the DGV are in textBox1 and textBox2.
I need that when the user is going to add a new row in the DGV the first two columns automatically fill with these constant values and set the focus to the third column.
Thanks in advance
If you don't want the user to edit the first two columns, just set their
ReadOnly
property to true:As for your other criteria, first set the following property to limit control of when a new row is added (ex. click of a button):
Then create your own method to add new rows when needed:
Technically, you could do this when
AllowUserToAddRows == true
by handling theDataGridView.RowsAdded
event and the above code slightly modified, but you'll get an annoying behavior where as soon as you enter one character into the new row, 3rd column, another new row is added and the editing cell loses focus (probably before you actually entered anything useful).