Upgrading to 2.5 from 1.0.2005 - EntityCollectionBase problem

Posts   
 
    
JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 27-Sep-2007 21:04:57   
        
public new object DataSource
{
  get { return base.DataSource;}
  set {
    EntityCollectionBase collectionbase = value as EntityCollectionBase;
    if (collectionbase != null)
    {   collectionbase.AllowNew = _allowNew;
        collectionbase.SupportsSorting = _allowSorting;
    }
    if (value!=null)
    {   if (this.TableStyles.Count >0)
        {   DataGridTableStyle dgts = this.TableStyles[0] as DataGridTableStyle;
            string mappingname = RetrieveMappingName(value);
            dgts.MappingName =  mappingname;
        }
    }
    base.DataSource = value;

        Grid_SizeChanged(null, null);
    this.Focus();
    }
}

Hi,

My problem is with the EntityCollectionBase collectionbase = value as EntityCollectionBase; code ... under the previous version this works fine ... in the 2.5 version (due to the generics) it breaks ...

property is used to fill a custom made datagrid with a llblgen collection need the allownew to disable the empty last row ... setting the allowrow on the collection before assigning the collection to the datasource of the custom datagrid does not work ... nor casting the collection to iEntityCollectionBase and setting the allownew off ...

any ideas?

Thx

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2007 10:31:08   

Try entityCollection.DefaultView.AllowNew = false

JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 28-Sep-2007 13:10:47   

changed (it didnt compile)

EntityCollectionBase collectionbase = value as EntityCollectionBase;

to

IEntityCollection _List = value as IEntityCollection;
_List.DefaultView.AllowNew = true;

But i keep getting the empty row in the grid ...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39948
Joined: 17-Aug-2003
# Posted on: 28-Sep-2007 16:26:33   

AllowNew should be FALSE.

Also, most of the time you need to set this in the grid to disable it completely (don't ask me why, some grids want to offer a 'new row' edit line no matter what. wink )

Frans Bouma | Lead developer LLBLGen Pro
JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 28-Sep-2007 16:30:20   

setting the allownew to false did it ...

fridayafternoon confused ...

Thx

JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 01-Oct-2007 15:35:44   

Ok, all grids work except 1 ...

Binding a grid (detail) to a list box (master) ...

lstLocaties.DisplayMember = "LocaleDesc";
lstLocaties.DataSource = m_currentEntity.LocationCode;
gridLocatieOmschrijvingen.DataSource = m_currentEntity.LocationCode;
gridLocatieOmschrijvingen.DataMember = "LocationCodeLocale";

LocationCodeLocale is a collection on a LocationCode entity ...

Setting the AllowNew property, on the default view of the LocationCode collection, to FALSE does not work here becaus "LocationCodeLocale" is a subcollection ...

How can i solve this? Thx

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Oct-2007 13:09:57   

Is this .NET +2.0 or .NET 1.x?

JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 02-Oct-2007 13:12:51   

.NET 2.0

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Oct-2007 13:17:24   

in .NET 2 you can disable the new row from the Grid's properties. (EnableAdding / AllowUserToAddRows)

JoeriSoete
User
Posts: 14
Joined: 26-Sep-2007
# Posted on: 02-Oct-2007 14:42:56   

that would be the easiest solution if it was a DataGridView, unfortunately the previous programmer used an DataGrid wich doesn't expose a AllowNew or AllowUserToAddRows property ...

luckily i found that he manually filled the collection and subcollection ... so i was able to set the DefaultView.AllowNew = false for all the subcollections at the moment they were created ...

thx anyway for your help