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...

Who is Participating?
Sudhakar PulivarthiConnect With a Mentor Project Lead - EngineeringCommented:

You can add rows to the grid as follows.
I have added three columns, 2 columns are textbox and third is check box,
accordingly i place the values for my row added to the grid.

 int index = dataGridView1.Rows.Add(); // Provides a row and adds to the collection
dataGridView1.Rows[index].Cells[0].Value = "1"; // Provide values for each row cells
dataGridView1.Rows[index].Cells[1].Value = "2";
dataGridView1.Rows[index].Cells[2].Value = "True";
HainKurtSr. System AnalystCommented:
maybe something like this:

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

then bind it to your dataGrid...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.