?
Solved

Adding a new row in an unbound DataGridView

Posted on 2011-09-27
2
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

762 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