WPF Databinding ListView

Posts   
 
    
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 16-Oct-2007 23:09:33   

I am binding my EntityCollection to a WPF listview.

<ListView.View>
        <GridView>
            <GridViewColumn Header="Device" DisplayMemberBinding="{Binding LogGroup.Hour}"/>
            <GridViewColumn Header="Type" DisplayMemberBinding="{Binding LogEventEntryTypeId}"/>
            <GridViewColumn Header="Time" DisplayMemberBinding="{Binding AirStarttime}"/>
            <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}"/>
        </GridView>
    </ListView.View>

I get an AmbiguousMatchException "Ambigious match found." for the LogGroup.Hour binding.

This is my sample code. The DbLogGroup and DbLogEvent are the EntitySubClasses (template changed from My"Table"Entity to DB"Table")

ArrayList arr = new ArrayList();
                
                DbLogGroup grp = new DbLogGroup();
                grp.Hour = 0;
                DbLogEvent evt = new DbLogEvent();
                evt.LogEventEntryTypeId = 3;
                evt.AirStarttime = DateTime.Now;
                evt.Description = "Test 1";
                evt.LogGroup = grp;
                arr.Add(evt);

                grp = new DbLogGroup();
                grp.Hour = 1;
                evt = new DbLogEvent();
                evt.LogEventEntryTypeId = 100;
                evt.AirStarttime = DateTime.Now;
                evt.Description = "Test 2";
                evt.LogGroup = grp;
                arr.Add(evt);

                m_logCtrl.LogList.DataContext = arr;

If I replace this with an non LLBLGen generated class then I do not get the exception.

ArrayList arr = new ArrayList();
                arr.Add(new LogItem(1, DateTime.Now, "Test 1", 0));
                arr.Add(new LogItem(2, DateTime.Now, "Test 2", 1));

Any ideas why I get the AmbiguousMatchException?

I attached the code for my class and the Generated class(just the metadata)

Attachments
Filename File size Added on Approval
Code.cs 16,029 16-Oct-2007 23:10.59 Approved
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Oct-2007 12:45:44   

Did you try the using the following:

<GridViewColumn Header="Device" DisplayMemberBinding="{Binding DBLogGroup.Hour}"/>

instead of:

<GridViewColumn Header="Device" DisplayMemberBinding="{Binding LogGroup.Hour}"/>
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 17-Oct-2007 17:02:49   

I did. I get this in my output and the data does not get displayed

System.Windows.Data Error: 35 : BindingExpression path error: 'DbLogGroup' property not found on 'object' ''DbAudioEvent' (HashCode=36635)'. BindingExpression:Path=DbLogGroup.Hour; DataItem='DbAudioEvent' (HashCode=36635); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

I also tried binding though code but that didn't work either.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 19-Oct-2007 12:10:08   

The property is simply there, according to the code. The LogGroup property returns a LogGroupEntity, which has an Hour property. I fail to see why this gives an error as there's just 1 Hour property in that inheritance chain.

Your LogItem class to check whether it works with normal classes isn't equal to the LogGroup - DbGroup inheritance hierarchy.

You should test with a class DbGroup which inherits from Group and which is set to a value inside LogItem, not with Group, as in your entity setup, you test with DbGroupEntity, while Hour is defined in its supertype, LogGroupEntity.

Please check this MSDN forums thread which discusses the same issue: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2263277&SiteID=1

Frans Bouma | Lead developer LLBLGen Pro
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 26-Oct-2007 23:46:05   

I added the namespace

xmlns:DAL="clr-namespace:RCS.Bengal.Dal.EntityClasses"

and this binding

<GridViewColumn Header="Hour" DisplayMemberBinding="{Binding Path=(DAL:DbLogEvent)LogGroup.Hour}"/>

but I still get this error

System.Windows.Data Error: 35 : BindingExpression path error: '(DAL:DbLogEvent)LogGroup' property not found on 'object' ''DbLogEvent' (HashCode=42098)'. BindingExpression:Path=(DAL:DbLogEvent)LogGroup.Hour; DataItem='DbLogEvent' (HashCode=42098); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 35 : BindingExpression path error: '(DAL:DbLogEvent)LogGroup' property not found on 'object' ''DbAudioEvent' (HashCode=42099)'. BindingExpression:Path=(DAL:DbLogEvent)LogGroup.Hour; DataItem='DbAudioEvent' (HashCode=42099); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

Am I doing this wrong?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2007 07:57:46   

koushikks wrote:

and this binding

<GridViewColumn Header="Hour" DisplayMemberBinding="{Binding Path=(DAL:DbLogEvent)LogGroup.Hour}"/>

Are you casting _LogGroup _to DBLogEvent? Shouldn't be DAL : DBLogGroup?

David Elizondo | LLBLGen Support Team
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 31-Oct-2007 23:44:08   

I tried a bunch of other ways but I am obviously not casting or specifying the item right and I can't figure out what I am doing wrong.

<GridViewColumn Header="Hour" DisplayMemberBinding="{Binding Path=(DAL:DbLogGroup)LogGroup.Hour}"/>
System.Windows.Data Error: 35 : BindingExpression path error: '(DAL:DbLogGroup)LogGroup' property not found on 'object' ''DbAudioEvent' (HashCode=46097)'. BindingExpression:Path=(DAL:DbLogGroup)LogGroup.Hour; DataItem='DbAudioEvent' (HashCode=46097); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 35 : BindingExpression path error: '(DAL:DbLogGroup)LogGroup' property not found on 'object' ''DbLogEvent' (HashCode=46098)'. BindingExpression:Path=(DAL:DbLogGroup)LogGroup.Hour; DataItem='DbLogEvent' (HashCode=46098); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 04-Nov-2007 13:26:37   

Did you read teh msdn link I linked to?

Frans Bouma | Lead developer LLBLGen Pro
koushikks
User
Posts: 9
Joined: 23-May-2007
# Posted on: 09-Nov-2007 16:58:23   

Yes I did and tried "type-casting" the binding bath to the object property that I need as in my previous posts.

Am I doing it wrong? Or did I misunderstand the msdn post?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 11-Nov-2007 11:20:07   

I've no idea. I think it's a WPF related issue and your problem seemed exactly what the thread was all about, but I can't help you further, as it doesn't seem to be an LLBLGen pro related problem.

Frans Bouma | Lead developer LLBLGen Pro
philipp
User
Posts: 53
Joined: 15-Feb-2007
# Posted on: 01-Dec-2007 12:32:47   

Otis wrote:

I've no idea. I think it's a WPF related issue and your problem seemed exactly what the thread was all about, but I can't help you further, as it doesn't seem to be an LLBLGen pro related problem.

This might be an issue with the EntityCollection<T> class in WPF. I have a similar issue with an extended entity class:

LLBL generated class: GroupEntity My custom class: _SyncGroup _(extends GroupEntity)

I'm trying to bind an EntityCollection<SyncGroup> to an Infragistics grid. This works fine as long as I only specify properties of the GroupEntity class. As soon as I try to include a property of my _SyncGroup _(e.g. SyncStatus), the grid fails.

Now here's the thing: If i take my EntityCollection<SyncGroup> and copy all its items to a List<SyncGroup> and bind the list rather than EntityCollection<SyncGroup>, everything works like a charm. I'm in desperate need of a solution - help wink

Thanks for your advice Philipp

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Dec-2007 08:24:57   

Would you please attach the code of the custom class?

P.S. please don't hijack older threads, next time please create a new one.

philipp
User
Posts: 53
Joined: 15-Feb-2007
# Posted on: 03-Dec-2007 10:26:33   

Walaa wrote:

Would you please attach the code of the custom class?

Walaa

thanks for the feedback. Please find attached an entity implementation. The problem is, however, reproducable with all my custom entities. Regarding the hijacked thread: Will do, sorry.

using System.Collections.Generic;
using System.ComponentModel;
using CT.DataAccess.Entities.EntityClasses;
using CT.DataAccess.Entities.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace CT.Core.DataAccess.Synchronization
{
  /// <summary>
  /// Extends a <see cref="GroupEntity"/> with synchronization
  /// flags.
  /// </summary>
  public class SyncGroup : GroupEntity, ISynchronizable<SyncGroup>
  {
    #region fields

    /// <summary>
    /// The synchronization status of the group. Defaults
    /// to <see cref="Synchronization.SyncStatus.Undefined"/>.
    /// </summary>
    private SyncStatus syncStatus = SyncStatus.Undefined;

    /// <summary>
    /// The corresponding item in the other data store to which
    /// this instance is being compared. Defaults to null.
    /// </summary>
    private SyncGroup syncItem = null;

    #endregion


    #region properties

    /// <summary>
    /// Gets or sets the synchronization status of the group.
    /// Defaults to <see cref="Synchronization.SyncStatus.Undefined"/>.
    /// </summary>
    public SyncStatus SyncStatus
    {
      get { return syncStatus; }
      set
      {
        syncStatus = value;
        OnPropertyChanged("SyncStatus");
      }
    }


    /// <summary>
    /// The corresponding item in the other data store to which
    /// this instance is being compared. Defaults to null.
    /// </summary>
    [Browsable(false)]
    public SyncGroup SyncItem
    {
      get { return syncItem; }
      set
      {
        syncItem = value;
        OnPropertyChanged("SyncItem");
      }
    }


    /// <summary>
    /// Gets an enumerator that provides recursive browsing through
    /// all child groups of the current group.
    /// </summary>
    [Browsable(false)]
    public IEnumerable<SyncGroup> RecursiveList
    {
      get { return BrowseGroups(this); }
    }

    #endregion


    #region construction

    /// <summary>
    /// Creates an empty entity with an initial synchronization
    /// status of <see cref="Synchronization.SyncStatus.Undefined"/>.
    /// </summary>
    public SyncGroup()
    {
    }


    /// <summary>
    /// Creats an entity for a given group with an initial synchronization
    /// status of <see cref="Synchronization.SyncStatus.Undefined"/>.
    /// </summary>
    /// <param name="groupId">The unique ID of the data point.</param>
    public SyncGroup(int groupId)
      : base(groupId)
    {
    }


    /// <summary>Constructor for internal framework usage.</summary>
    /// <remarks>For framework usage.</remarks>
    /// <param name="fields">Fields object to set as the fields for this entity.</param>
    internal SyncGroup(IEntityFields2 fields)
      : base(fields)
    {
    }

    #endregion


    #region get strongly typed child collections

    /// <summary>
    /// Gets the contents of the <see cref="GroupEntity.ChildGroups"/>
    /// collection, but as a strongly typed collection of <see cref="SyncGroup"/>
    /// instances.
    /// </summary>
    /// <returns>All child groups of the instance.</returns>
    public EntityCollection<SyncGroup> SyncChildGroups
    {
      get
      {
        EntityCollection<SyncGroup> groups;
        groups = new EntityCollection<SyncGroup>(SyncGroupFactory.Instance);
        foreach (SyncGroup childGroup in ChildGroups)
        {
          groups.Add(childGroup);
        }
        return groups;
      }
    }


    /// <summary>
    /// Gets the contents of the <see cref="GroupEntity.DataPoints"/>
    /// collection, but as a strongly typed collection of <see cref="SyncDataPoint"/>
    /// instances.
    /// </summary>
    /// <returns>All child data points of the instance.</returns>
    public EntityCollection<SyncDataPoint> SyncDataPoints
    {
      get
      {
        EntityCollection<SyncDataPoint> dataPoints;
        dataPoints = new EntityCollection<SyncDataPoint>(SyncDataPointFactory.Instance);
        foreach (SyncDataPoint dataPoint in DataPoints)
        {
          dataPoints.Add(dataPoint);
        }
        return dataPoints;
      }
    }

    #endregion


    #region browse groups recursively

    /// <summary>
    /// Recursively browses all items of a given data point group.
    /// </summary>
    /// <param name="root">The root group that contains the immediate
    /// childs to be processed.</param>
    /// <returns>Group enumerator.</returns>
    public static IEnumerable<SyncGroup> BrowseGroups(SyncGroup root)
    {
      //return the root element
      yield return root;

      //process child groups
      foreach (SyncGroup group in root.ChildGroups)
      {
        //perform recursive call
        foreach (SyncGroup sub in BrowseGroups(group))
        {
          yield return sub;
        }
      }
    }

    #endregion


    #region resolve sync status

    /// <summary>
    /// Resolves the synchronization status with regards to parent groups
    /// and nested content. Rules are as follows:
    /// <list type="bullet">
    /// <item>If the parent group will be deleted, so will this group.</item>
    /// <item>If the group has been modified, the local status will be returned.</item>
    /// <item>If the group itself has not been changed but a nested group or data
    /// point was modified or deleted, this method returns a value of
    /// <see cref="Synchronization.SyncStatus.Changed"/>.</item>
    /// </list>
    /// </summary>
    /// <returns>The resolved status.</returns>
    public SyncStatus ResolveSyncStatus()
    {
      return ResolveSyncStatus(true);
    }


    /// <summary>
    /// Resolves the synchronization status with regards to parent groups
    /// and nested content. Rules are as follows:
    /// <list type="bullet">
    /// <item>If the parent group will be deleted, so will this group.</item>
    /// <item>If the group has been modified, the local status will be returned.</item>
    /// <item>If the group itself has not been changed but a nested group or data
    /// point was modified or deleted, this method returns a value of
    /// <see cref="Synchronization.SyncStatus.Changed"/>.</item>
    /// </list>
    /// </summary>
    /// <param name="handleParentGroups">Whether to check whether the group's
    /// parent have been deleted or not. May be set to false when recursively
    /// browsing the groups.</param>
    /// <returns>The resolved status.</returns>
    public SyncStatus ResolveSyncStatus(bool handleParentGroups)
    {
      //if there is no parent group, return the local status
      if (handleParentGroups)
      {
        //first check if locally marked for deletion before doing that amount
        //of work
        if (syncStatus == SyncStatus.Deleted) return SyncStatus.Deleted;

        //if the parent group will be deleted, so will be this one
        SyncGroup group = ParentGroup as SyncGroup;
        if (group != null && group.ResolveIsDeleted()) return SyncStatus.Deleted;
      }

      //check the local status - if the group itself was changed, use the local group status
      if (syncStatus != SyncStatus.Synced && syncStatus != SyncStatus.Local && syncStatus != SyncStatus.New)
        return syncStatus;

      //the local group has not been modified, so check nested content. Start with data points
      foreach (SyncDataPoint dataPoint in MergedDataPoints)
      {
        SyncStatus pointStatus = dataPoint.SyncStatus;
        if (pointStatus == SyncStatus.Local && syncStatus != SyncStatus.Local ||
            pointStatus == SyncStatus.New && syncStatus != SyncStatus.New)
        {
          //-> if a child is Local or New and this group isn't, this is a change
          return SyncStatus.Changed;
        }
        else if (pointStatus != SyncStatus.Synced && pointStatus != SyncStatus.Local && pointStatus != SyncStatus.New)
        {
          //whatever the modification is - mark as changed
          return SyncStatus.Changed;
        }
      }

      //check the status of the nested child groups and their data points
      //-> they don't have to check their parente anymore, that's the current group
      foreach (SyncGroup childGroup in MergedChildGroups)
      {
        SyncStatus groupStatus = childGroup.ResolveSyncStatus(false);
        if (groupStatus == SyncStatus.Local && syncStatus != SyncStatus.Local ||
            groupStatus == SyncStatus.New && syncStatus != SyncStatus.New)
        {
          //-> if a child is Local or New and this group isn't, this is a change
          return SyncStatus.Changed;
        }
        else if (groupStatus != SyncStatus.Synced && groupStatus != SyncStatus.Local && groupStatus != SyncStatus.New)
        {
          //whatever the modification is - mark as changed
          return SyncStatus.Changed;
        }
      }

      //return the local status (synced or local or new)
      return syncStatus;
    }


    /// <summary>
    /// Verifies if the group is marked for deletion by checking its local
    /// <see cref="SyncStatus"/> as well as the status of the group's
    /// parents.
    /// </summary>
    /// <returns>True if the group is being deleted directly or implicitely
    /// by deleting one of its parent groups.</returns>
    public bool ResolveIsDeleted()
    {
      if (syncStatus == SyncStatus.Deleted)
      {
        return true;
      }
      else
      {
        SyncGroup parentGroup = ParentGroup as SyncGroup;
        return parentGroup == null ? false : parentGroup.ResolveIsDeleted();
      }
    }

    #endregion


    #region get merged child collections

    /// <summary>
    /// Gets a collection which contains all child groups of
    /// this instance's <see cref="GroupEntity.ChildGroups"/> collection
    /// plus all child groups of the <see cref="SyncItem"/> instance which
    /// do not have a corresponding entry in this group.
    /// </summary>
    /// <returns>A collection that contains all local child groups of this
    /// group plus items of the corresponding <see cref="SyncItem"/> group
    /// that have no corresponding item in this group.</returns>
    public EntityCollection<SyncGroup> MergedChildGroups
    {
      get
      {
        //get all local childs
        EntityCollection<SyncGroup> groups = SyncChildGroups;

        //if there is no corresponding sync group, we're done
        if (syncItem == null) return groups;

        //find all remote child groups without a corresponding entry in this instance
        foreach (SyncGroup group in SyncItem.ChildGroups)
        {
          //not only orphanced items are candidates, but moved ones as well, as their
          //corresponding item is in another group - so it's not in our local collection
          SyncStatus status = group.SyncStatus;
          //the 3rd condition is needed during initialization - items may be linked, but
          //there status (moved) has not yet been determined. This would already cover the
          //2nd condition, but the 2nd one's much faster, so keep it
          if (group.SyncItem == null || status == SyncStatus.Moved || !groups.Contains(group.SyncItem))
          {
            groups.Add(group);
          }
        }

        return groups;
      }
    }


    /// <summary>
    /// Gets a collection which contains all data points of
    /// this instance's <see cref="GroupEntity.DataPoints"/> collection
    /// plus all data points of the <see cref="SyncItem"/> instance which
    /// do not have a corresponding entry in this group.
    /// </summary>
    /// <returns>A collection that contains all local data points of this
    /// group plus items of the corresponding <see cref="SyncItem"/> group
    /// that have no corresponding item in this group.</returns>
    public EntityCollection<SyncDataPoint> MergedDataPoints
    {
      get
      {
        EntityCollection<SyncDataPoint> points = new EntityCollection<SyncDataPoint>();
        foreach (SyncDataPoint point in DataPoints) points.Add(point);

        //if there is no corresponding sync group, we're done
        if (syncItem == null) return points;

        //find all remote data points without a corresponding entry in this instance
        foreach (SyncDataPoint point in SyncItem.DataPoints)
        {
          //not only orphanced items are candidates, but moved ones as well, as their
          //corresponding item is in another group - so it's not in our local collection
          SyncStatus status = point.SyncStatus;
          //the 3rd condition is needed during initialization - items may be linked, but
          //their status (moved) has not yet been determined. This would already cover the
          //2nd condition, but the 2nd one's much faster, so keep it
          if (point.SyncItem == null || status == SyncStatus.Moved || !points.Contains(point.SyncItem))
          {
            points.Add(point);
          }
        }

        return points;
      }
    }

    #endregion
  }
}
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 04-Dec-2007 14:23:05   

(please next time attach a file wink )

philipp wrote:

Otis wrote:

I've no idea. I think it's a WPF related issue and your problem seemed exactly what the thread was all about, but I can't help you further, as it doesn't seem to be an LLBLGen pro related problem.

This might be an issue with the EntityCollection<T> class in WPF. I have a similar issue with an extended entity class:

LLBL generated class: GroupEntity My custom class: _SyncGroup _(extends GroupEntity)

I'm trying to bind an EntityCollection<SyncGroup> to an Infragistics grid. This works fine as long as I only specify properties of the GroupEntity class. As soon as I try to include a property of my _SyncGroup _(e.g. SyncStatus), the grid fails.

Now here's the thing: If i take my EntityCollection<SyncGroup> and copy all its items to a List<SyncGroup> and bind the list rather than EntityCollection<SyncGroup>, everything works like a charm. I'm in desperate need of a solution - help wink

Thanks for your advice Philipp

List<T> with infragistics will use a reflection based approach. So it will see any properties. With an entitycollection in winforms/wpf, that's not the case, it will use ITypedList on the entityview returned by the entitycollection

The problem you're facing is that the FACTORY in the entitycollection produces GroupEntity instances. So when the collection is requested for the properties of its contained elements, it creates a dummy, checks the properties and returns those.

As you have a factory of the groupentity type in the collection, you won't see SyncGroup properties. Create a factory, derived from GroupEntityFactory which produces a SyncGroup instance instead of a GroupEntity and set that factory as the factory of the collection.

Frans Bouma | Lead developer LLBLGen Pro
philipp
User
Posts: 53
Joined: 15-Feb-2007
# Posted on: 06-Dec-2007 10:17:24   

Works like a charm! Thanks a lot simple_smile

ferhaad
User
Posts: 5
Joined: 05-Nov-2007
# Posted on: 28-Jan-2008 23:53:05   

Hi there,

I have posted a query few days back with the Thread Title: How to override a collection type for binding to a DataGrid

Thread URL: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12389

Hey Philip I am working the same scenario and I think you can help me. I have got 2 issues. One with LLBLGEN and other with Infragistic.

(IN LLBLGEN)How do I override the base class Collection PROPERTY other than iterating through the collection and copying each base class object. For detail of my class hierarchy please refer to the above mentioned thread. If I could get a sample derived class and it's corresponding Factory class that would be great.

And 2nd issue is with Infragistic. My comboBox within the XamDatagrid won't load when bound to the derived class collection?

Any help is appreciated.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Jan-2008 09:56:40   

(IN LLBLGEN)How do I override the base class Collection PROPERTY other than iterating through the collection and copying each base class object. For detail of my class hierarchy please refer to the above mentioned thread. If I could get a sample derived class and it's corresponding Factory class that would be great.

Is this the same question as posted in your other mentioned thread, if so why don't you reply there, so we can further discuss it.

Are you speaking about overriding a related collection property inside an entity class? As far as I know properties can't be overriden. But you can create another property in parallel, and use it instead, with the appropriate factory.

And 2nd issue is with Infragistic. My comboBox within the XamDatagrid won't load when bound to the derived class collection?

Would you please provide more details? Are you using a normal entityCollection of a derived entity class? Or are you using a derived entityCollection class of normal entity class.

ferhaad
User
Posts: 5
Joined: 05-Nov-2007
# Posted on: 29-Jan-2008 16:06:14   

Hi,

Regarding the first collection of overriding properties. I have done successfully in my derived class. Am stuck with overriding Collection Property of related entity in my derived class. Anyhow that whole scenario is explained in that thread along with the code snippet.

Regarding Q2. I can bind my derived collection to the comboBox outside of the XamDatagrid but when it comes to binding within the XamDataGrid. It doesn't work. Get the following exception. Is there a property conflict between my derived class and Base Class?

System.ArgumentException was unhandled

Message="value isn't of the correct type."

Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"

StackTrace:

   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.IndexOf(Object value)

   at System.Windows.Data.BindingListCollectionView.InternalIndexOf(Object item)

   at System.Windows.Data.BindingListCollectionView.IndexOf(Object item)

   at System.Windows.Controls.ItemCollection.IndexOf(Object item)

   at System.Windows.Controls.ItemsControl.NavigateToItem(Object item, Int32 elementIndex, ItemNavigateArgs itemNavigateArgs, Boolean alwaysAtTopOfViewport)

   at System.Windows.Controls.ComboBox.<OnIsDropDownOpenChanged>b__1(Object arg)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.DispatcherOperation.InvokeImpl()

   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)

   at System.Threading.ExecutionContext.runTryCode(Object userData)

   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Windows.Threading.DispatcherOperation.Invoke()

   at System.Windows.Threading.Dispatcher.ProcessQueue()

   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.Run()

   at System.Windows.Application.RunInternal(Window window)

   at System.Windows.Application.Run(Window window)

   at System.Windows.Application.Run()

   at RCS.Bengal.NavigationControl.App.Main() in C:\Projects\Bengal\main\Bengal\vs2008\Bengal.UI\NavigationControl\NavigationControl\obj\Debug\App.g.cs:line 0

   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadHelper.ThreadStart()

InnerException:

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 31-Jan-2008 10:24:22   

The object passed into IList.IndexOf isn't castable to the generic argument of the entityview. So if the entitycollection has entities of type T, and IndexOf gets an object passed in which isn't castable to T, you'll get this error. Please check your code.

A general piece of advice: choose partial classes over inheritance in this case.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39858
Joined: 17-Aug-2003
# Posted on: 14-Feb-2008 13:31:35   

We identified the issue: WPF passes 'null' to the IndexOf method. No idea why it does that, but we've patched the runtime: See this message: http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=69494&ThreadID=12513

Frans Bouma | Lead developer LLBLGen Pro