Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "finalize" a new row

So I've been running into some trouble tonight with my c# windows forms application. Is it possible to insert a new row to a datagridview when the currently selected new row is still on its default values? Or, if I want to change the values programmatically, how can I emulate the user editing the textbox in order to finalize the row?

To clarify, when a row is a new row (and shows up as true with the isNewRow property), I cannot figure out how to change out of the isNewRow = true state to generate a new empty row below.

I've tried dataGridView.EndEdit(), dataGridView.CurrentRow.DataGridView.EndEdit(), bindingSource.EndEdit(), and none of these have really done the trick. (also, using dataGridView.BeginEdit() puts the text box into editmode, which isn't handy, because I can't seem to edit the cell programmatically after that)

Ideally, I would like to be able to continue to hit enter on new rows, while changing their values with a custom control, or not, and have a new row appear underneath.

Does anyone have any solutions to this?

like image 291
Harrison Lambeth Avatar asked May 28 '13 03:05

Harrison Lambeth


Video Answer


1 Answers

Okay so I figured how to make this work. When modifying the values using my custom control, I had to use

bindingSource.EndEdit();
dataGridView.NotifyCurrentCellDirty(true);
dataGridView.EndEdit();
dataGridView.NotifyCurrentCellDirty(false);

So whenever changes are made to the new row, it forces the row to be committed and adds a new blank row space to the end of the datagridview.

I did not have to use Validate(), however.

like image 65
Harrison Lambeth Avatar answered Sep 28 '22 07:09

Harrison Lambeth