I`m using VS 2008, Win Forms, C# 3.5
How do I go about adding rows to a Data Grid View that is databound with a List. Let me simplify and explain what I`m trying to do.
I have a User Control which consists of a DataGridView and few other controls. And I want to add and delete rows in the Data Grid View. When I add rows, I want a blank row to be inserted and the user can type in some values at a particular index.
In the main form I have an event which loads the data into the DataGridView
CustUserCntrl CX = new CustUserCntrl(); //Contains the Data Grid View
BindingSource BS = new BindingSource();
BS.DataSource = CreateDummList(); //This returns a List of objects of some class.
CX.MotGridView.DataSource = BS;
I saw a few example of adding rows programtically in a Data Grid View by using Data Sets. But I`m using Lists here.
In the User Control Code [CustUserCntrl ] I have something like this -
private void AddMotRow()
// What goes in here?
//Deleting rows works
private void DeleteMotRow()
if (this.MotGridView.SelectedRows.Count > 0 && this.MotGridView.SelectedRows.Index != this.MotGridView.Rows.Count - 1)
Also, is there a way to copy and paste rows in the DataGridView?