tags:

views:

78

answers:

2

I want to add a new row to a datagridview such that when a user clicks on new button , a new is is generated with few textboxes and combo boxes and after filling up all the details he save the info by clicking on save button.

EDIT

I want to do it like it is seen in gridview(Template Fields) in asp.net I am looking for same kind of functionality.

A: 

Assuming your _dataGridView.Columns collection is not null and contains a template of the rows you wish to add, it is as simple as something like this:

foreach(var item in _collection)
{
    _dataGridView.Rows.Add(item.Foo, item.Bar);
}

In order for this to work, you will have had to design your Columns collection in the VisualStudio designer or programatically add DataGridViewTextBoxColumn objects to the Columns collection.

In the example above, I added two DataGridViewTextBoxColumn objects to the _dataGridView.Columns collection and then populated the datagrid from a List of my object that contained a 'Foo' and a 'Bar'.

EDIT

Have you checked out the DataGridView FAQ? The information about using the DataGridView in unbound mode may help you.

HTH

AlfredBr
A: 

Since I'm not sure exactly how you want to achieve this.. I would have a hidden panel with your text boxes, ...etc, show the panel when the new button is clicked. After all information is entered into the fields, click the save button. Assuming that you will be inserting this information into a table, after the row is inserted, call the stored procedure to get the desired records from the table being displayed in the grid.

Avien