Solved

Adding a new row in an unbound DataGridView

Posted on 2011-09-27
2
358 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 51

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COnsume rest client 6 36
C# replace string in void with dR["myData"].ToString() 3 41
Remove greater than sign 3 45
C# HTTP GET method sample code 3 41
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now