Q:

Manually set the properties of new objects created from datagridview

premise: I have a class "User" which has a property of type list to represent a list of "Office" associated with the user.
I have a BindingSource associated to the list of "Office" in which the grid is hooked to insert new elements.
Everything seems to work correctly, when I click on the new line and write a value in the list is added to the new object "Office"
The problem is that in addition to the data entered by the user I want to insert some default value automatically (example: a guid), I know I could do this with a hidden column in my grid, but I do not like too much as a solution and I would like to work directly on the object .
I tried with the event
DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.databindingcomplete%28v=vs.110%29.aspx
This is called after the new object "office" was added to the list but I can not recover it, because I do not know which row is inserted but only a generic word "ItemAdded"
I also tried using the method
DefaultValuesNeeded(object sender, System.Windows.Forms.DataGridViewRowEventArgs e)

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.defaultvaluesneeded%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
but this to me is called before my object "office" I is added to the list and I have no way to have it in order to set the default.
Long story short: how do I manually set the values on the properties of an object added to a list automatically from gridview without using hidden columns?

A:

If the Property "guid" is generated from the Entity Framework, then you can add a partial class such as:
public partial class Office
{
   public Office()
   {
        guid=Guid.newGuid();
   }
}

and add a constructor there which populates the guid property whenever a new office is created.

