?
Solved

Adding a new row in an unbound DataGridView

Posted on 2011-09-27
2
Medium Priority
?
394 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:collages
2 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 36711822
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...
0
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 2000 total points
ID: 36714505
Hi,

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";
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question