views:

284

answers:

2

I am using a Datagridview (unbounded mode) and I have selected "enable adding" in the designer.

when the form loads, the grid is not populated (drop down to select a supplier and button to view aliases) and there is a single row displayed with the * in the tab.

However, when I populate the grid, I no longer have this insert row for adding to the collection.

Here's basically what I am doing:

List<SupplierAlias> aliases = //some db lookup.
aliasGrid.AutoGenerateColumns = false;
aliasGrid.DataSource = aliases;

The columns are defined as unbound columns in the designer.

Previously, I was using clearing the aliasGrid.DataBindings but I took that out and it still removes the insert row.

A: 

Does SupplierAlias have a public parameterless constructor? If it doesn't, you'll need to use an IBindingList implementation to provide the new row - for example BindingSource:

    BindingSource bs = new BindingSource();
    bs.DataSource = yourList;
    bs.AddingNew += delegate(object sender, AddingNewEventArgs args)
    {
        args.NewObject = new SomeType(args);
    };
    grid.DataSource = bs;
Marc Gravell
It does have a public parameterless constructor which just sets its ID to a new guid.
Drithyin
A: 

Answering own question for others' reference.

I changed the List<SupplierAlias> I used to databind to a BindingList<SupplierAlias> and I have my insert row now.

Drithyin