Home Forums WPF controls Xceed DataGrid for WPF DataGridCollectionViewSource problem

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24646 |

    I tried to change CollectionViewSource to DataGridCollectionViewSource and suddenly no data is populated. I use CollectionViewSource binding to ObjectDataProvider. Is there anything I should be aware of?

    Thanks!

    Imported from legacy forums. Posted by nat (had 934 views)

    Xceed Support
    Member
    Post count: 5658

    Have you installed VS2008 Beta2?

    Imported from legacy forums. Posted by Marcus [Xceed] (had 287 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re so right. I totally forgot about that. I saw it in FAQ earlier.

    Now it’s working but when I try to group by some column which is in another object,

    <xcdg:Column ReadOnly=”True” Title=”Submit Date” FieldName=”SubmitDate” Width=”95″ >
    <xcdg:Column.DisplayMemberBinding>
    <Binding Path=”LineItems.Group.SubmitDate”>
    </Binding>
    </xcdg:Column.DisplayMemberBinding>
    </xcdg:Column>

    it fails with the following exception:

    9/13/2007 1:46:18 PM:System.InvalidOperationException: The property name ‘SubmitDate’ does not exist.
    at Xceed.Wpf.DataGrid.DataGridGroupDescription.SetContext(DataGridCollectionView collectionView)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.GroupItems(Boolean sendResetNotification, Boolean triggerRootGroupChanged)
    at Xceed.Wpf.DataGrid.DataGridCollectionView.GroupDescriptions_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
    at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
    at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
    at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
    at System.Windows.Controls.ItemCollection.SynchronizeGroupDescriptions(NotifyCollectionChangedEventArgs e, ObservableCollection`1 origin, ObservableCollection`1 clone)
    at System.Windows.Controls.ItemCollection.GroupDescriptionsChanged(Object sender, NotifyCollectionChangedEventArgs e)

    Is there a way to make it work?

    Thanks!

    Imported from legacy forums. Posted by nat (had 579 views)

    User (Old forums)
    Member
    Post count: 23064

    1. It looks like I can’t use DataGridGroupDescription since it will validate against the list of properties in the object in IEnumerable itself. I won’t be able to use it if I want to refer to parent field. It may make more sense to remove the validation then.

    2. GroupByControl is hardcoded to use DataGridGroupDescription all the time. Therefore, I cannot really change the behavior by myself.

    3. I should be able to specify how I want to group item using GroupByControl. For example, if I drag the date column, I should be able to create my own groupdescription to group by day, month or year.

    Thanks!

    Imported from legacy forums. Posted by nat (had 270 views)

    User (Old forums)
    Member
    Post count: 23064

    any response from Xceed?

    Imported from legacy forums. Posted by nat (had 365 views)

    Xceed Support
    Member
    Post count: 5658

    Trying to reproduce this issue, I fell on the same behavior…

    I have filed a bug report for this.

    We will update this thread when we have more information on workarounds or fixes…

    However, I have a suggestion. Probably that if you created a property on the “root” object that remaps to the “child” property, you could make that work…

    I know that this is not optimal, but that could allow you to make you project work as intended for the mean-time.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 311 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, Marcus. I’d rather like a DataGridViewCollection where you use Binding at each column to obtain the value. That will be awesome since you will get the benefit of converter automatically. Ideally, those binding and conversion should be done at the View level and then at the grid level, it will be just simple binding.

    Imported from legacy forums. Posted by nat (had 219 views)

    Xceed Support
    Member
    Post count: 5658

    Hi, one of our developpers sends this workaround:

    XAML :
    <code>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_data”
    Source=”{Binding Source={x:Static local:CustomData.Data}}”>
    <xcdg:DataGridCollectionViewSource.ItemProperties>
    <xcdg:DataGridItemProperty Name=”FirstName”/>
    <xcdg:DataGridItemProperty Name=”LastName”/>
    <xcdg:DataGridItemProperty Name=”City”
    ValuePath=”Detail.City”
    DataType=”{x:Type s:String}”/>
    <xcdg:DataGridItemProperty Name=”Country”
    ValuePath=”Detail.Country”
    DataType=”{x:Type s:String}”/>
    </xcdg:DataGridCollectionViewSource.ItemProperties>
    </xcdg:DataGridCollectionViewSource>

    <xcdg:DataGridControl x:Name=”grdOrders”
    ItemsSource=”{Binding Source={StaticResource cvs_data}, Path=View}”>
    </code>
    Which is based on a data class as follows:

    <code>
    public class CustomData
    {
    public static readonly CustomData[] Data = new CustomData[]
    {
    new CustomData( “Frank”, “Cari”, new SubCustomData( “Longueuil”, “Canada” ) ),
    new CustomData( “Markus”, “Cari”, new SubCustomData( “Montreal”, “Canada” ) ),
    new CustomData( “Vicky”, “Cari”, new SubCustomData( “Quebec”, “Canada” ) )
    };

    public CustomData( string firstName, string lastName, SubCustomData detail )
    {
    m_firstName = firstName;
    m_lastName = lastName;
    m_detail = detail;
    }

    public string FirstName
    {
    get
    {
    return m_firstName;
    }
    set
    {
    m_firstName = value;
    }
    }

    public string LastName
    {
    get
    {
    return m_lastName;
    }
    set
    {
    m_lastName = value;
    }
    }

    public SubCustomData Detail
    {
    get
    {
    return m_detail;
    }
    set
    {
    m_detail = value;
    }
    }

    private string m_firstName;
    private string m_lastName;
    private SubCustomData m_detail;
    }

    public class SubCustomData
    {
    public SubCustomData( string city, string country )
    {
    m_city = city;
    m_country = country;
    }

    public string City
    {
    get
    {
    return m_city;
    }
    set
    {
    m_city = value;
    }
    }

    public string Country
    {
    get
    {
    return m_country;
    }
    set
    {
    m_country = value;
    }
    }

    private string m_city;
    private string m_country;
    }
    </code>

    As you can see, this solution uses the DataGridItemProperty along with its ValuePath to work around the original issue.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 400 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks! I just saw your post. It looks promising.

    Imported from legacy forums. Posted by nat (had 6593 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.