Using GridTableStyles with an EntityCollection

Posts   
 
    
Gary Paul
User
Posts: 3
Joined: 29-Sep-2004
# Posted on: 15-Oct-2004 21:19:44   

I am trying to setup custom columns with a WinForm datagrid using TableStyles. It appears that I am having difficulty with the MappingName property.

As per other posts I have verified that I am using proper cased Property names for the column MappingName. I believe my difficulty is with the TableStyle MappingName. I have an EntityCollection created as such:

EntityCollection allData = DataManager.GetAllData()

The GetAllData method creates the EntityCollection using a DataEntityFactory:

EntityCollection allData = new EntityCollection(new DataEntityFactory());

I then use the DataAccessAdapter.FetchEntityCollection(allData,null) to retreive the data. Returning allData;

No matter what I do the Grid will not associate the resulting TableStyle with the EntityCollection in use.

I have tried the following for the MappingName on the TableStyle:

allData DataEntity DataEntityCollection EntityCollection

I have seen other posts indicating the need to include "Collection" in the name.

Any Ideas????

Anyone else using the Adpter with windos datagrid?

How about with Infragistics controls like UltraGrid??

Gary

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Oct-2004 21:50:42   

Just for the logs and other users:

EntityCollection returns "" for ITypedList.GetListName(). This means that (apparently, I didn't know this until 1 hour ago) the DataGrid will use that name for the mappingname comparison. So you shouldn't add anything as mappingname, leave it blank.

Fixing this will be cumbersome, not because the code is difficult, it's not, but because any name returned from now on will break existing applications. That's why I'll leave it as it is now.

Frans Bouma | Lead developer LLBLGen Pro
alexfranke avatar
alexfranke
User
Posts: 13
Joined: 12-Apr-2005
# Posted on: 04-Aug-2005 20:05:00   

Woohoo! I'm been banging my head over this all morning! I should have thought to look here first!

alexfranke avatar
alexfranke
User
Posts: 13
Joined: 12-Apr-2005
# Posted on: 05-Aug-2005 17:10:46   

Okay -- to follow up on this, I'm having a problem getting an EntityCollection with a related EntityCollection to work in the datagrid -- I think because all of the IBindingList.GetListName()'s return "".

(adapter model) So if I fetch an EntityCollection called Customers, which contatains a pre-fecthed EntityCollection called Orders, and I want to use a DataTableStyle for Customers and a different one for Orders, then the Datagrid can't differentiate between the two when applying a table style becuase GetListName() always returns "".

When I click on the + next to the customer reord on the datagrid, it loads up the EntityCollection of orders, and then tries to pick the appropriate DataGridStyle for its ListName, which is "". Because there's already another style mapped to "", it just chooses the first one (Customers) and produces the error: "The (property) DataGridColumnStyle cannot be used because it is not associated with a Property or Column in the DataSource."

Is there any way to set the list name or is there a workaround?

Thanks, Alex

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Aug-2005 17:27:41   

Add this code to the EntityCollection class's user code region at the bottom:


public override string GetListName(PropertyDescriptor[] listAccessors)
{
    if((listAccessors==null)||listAccessors.Length==0)
    {
        return this.EntityFactoryToUse.Create().LLBLGenProEntityName + "Collection";
    }
    else
    {
        TypeContainedAttribute typeAttribute = (TypeContainedAttribute) listAccessors[listAccessors.Length-1].Attributes[typeof(TypeContainedAttribute)];
        if(typeAttribute==null)
        {
            return this.EntityFactoryToUse.Create().LLBLGenProEntityName + "Collection";
        }
        return ((IEntity2)Activator.CreateInstance(typeAttribute.TypeContainedInCollection)).LLBLGenProEntityName + "Collection";
    }
}

This then produces for a collection which contains CustomerEntity instances "CustomerEntityCollection"

I think that will be enough to make them distinguishable simple_smile (you then also have to update the other styles of course, as no collection now returns "" )

(edit): bugfix, my first attempt only returns the root entitycollection's name.

Frans Bouma | Lead developer LLBLGen Pro