I'm trying to create dt table with rowchanging eventhandler to assing
default value to "ProductNro" column.

if (e.Action == DataRowAction.Add)
{
Guid id = (Guid)e.Row["ContainerID"];
DataTable dt = (DataTable)sender;
DataView dv = dt.DefaultView;

dv.RowFilter = "ContainerID=" + "'" + e.Row["ContainerID"] + "'";
dv.RowStateFilter = DataViewRowState.CurrentRows;

dt.Columns["PacketNro"].DefaultValue = dv.Count;
}

It works almost, the problem is that the first new row doesn't get the
default value. It gets just a null value, but if I remove this row and
insert new one (in DataGrid) then it starts to calculate rows correcly and
gets the correct "ProductNro". It's not a problem if there is no rows
already in DataTable but since you have to add new Products in old invoices
then you get again the null problem.

How this is possible that the first row gets null but rows after first one
gets correct values? I have tested and found out that when first row is
added DataTable seems to be empy (row.count) but it still shows correctly
rows on my DataGrid.


Thanks,
Oka Morikawa