Link to home
Start Free TrialLog in
Avatar of collages
collagesFlag for United States of America

asked on

Adding a new row in an unbound DataGridView

I have a datagridview and i was hoping there was an easy method to create a new row based off of the datagridview.

for example:
DataGridViewRow dataGridViewRow = dataGridView.Rows[dataGridView.Rows.Add()];

Open in new window


Obviously gives me an instance of the row with the proper columns already bound to the row however if it's the first row in the DataGridView this will fire the SelectionChanged event.


I'm looking to get the exact same row with the proper columns already attached to it but not have it be added to the collection first so I can assign the proper values AND THEN attach it to the datagridview via the Rows.Add function.


I though this was posssible...



Thanks
Avatar of HainKurt
HainKurt
Flag of Canada image

maybe something like this:

    DataRowView rowView = myView.AddNew();
    // Change values in the DataRow.
    rowView["ColumnName"] = "New value";
    rowView.EndEdit();

then bind it to your dataGrid...
ASKER CERTIFIED SOLUTION
Avatar of Sudhakar Pulivarthi
Sudhakar Pulivarthi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial