I have 2 views I am creating off of an Organizations Addresses.
The main list has all addresses and I need to split them out by way of Physical addresses and Mailing addresses.
So, I fetch the entity and create 2 EntityView2 instances using the appropriate predicate expression.
When the form displays the main address datagridview displays all the addresses and the other 2 datagridviews display nothing.
Here is the code for the fetch and view creation:
organization.OrganizationId = 151;
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(organization);
physical = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == OrganizationAddressEntity.AddressTypePhysical));
mailing = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == OrganizationAddressEntity.AddressTypeMailing));
addressGrid.DataSource = organization.Address;
physicalGrid.DataSource = physical;
mailingGrid.DataSource = mailing;
Just in case, here is the code for OrganizationAddressEntity.AddressTypeMailing and OrganizationAddressTypePhysical:
// Current values for AddressType
// 2 Business
// 1 Mailing
// 0 Physical
public static int AddressTypeMailing
{
get
{
return 1;
}
}
public static int AddressTypePhysical
{
get
{
return 0;
}
}
All 3 datagridviews display the same columns and share a RowsAdded method.
Here is the code for it:
private void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
if (sender == null) { return; }
DataGridView grid = (DataGridView)sender;
if (grid.DataSource == null) { return; }
for (int i = e.RowIndex ; i < (e.RowIndex + e.RowCount); i++)
{
if (grid.Rows[i].DataBoundItem != null)
{
OrganizationAddressEntity entity = (OrganizationAddressEntity)grid.Rows[i].DataBoundItem;
if (entity != null && entity.Address != null)
{
grid.Rows[i].Cells[0].Value = entity.AddressType.Name;
grid.Rows[i].Cells[1].Value = entity.Address.FirstStreetName;
grid.Rows[i].Cells[2].Value = entity.Address.CityTown.Name;
grid.Rows[i].Cells[3].Value = entity.Address.State.Code;
grid.Rows[i].Cells[4].Value = entity.Address.ZipPostalCode.Value;
}
}
}
}
What I am seeing is that when the main address grid enters the rowsadded method all is well. When the other 2 enter the method the cast to OrganizationAddressEntity is successful but the all of the child properties, AddressType / Address etc.., are null.
What am I missing??
Thanks.