This is a migrated thread and some comments may be shown as answers.

[Solved] Rebind() COM Error

4 Answers 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
invDev
Top achievements
Rank 1
invDev asked on 28 Feb 2011, 11:43 AM
Hello,

I have a strange problem with the DataGrid in the following situation. The DataSource is an ObservableCollection and each row has a custom UserControl as its DetailsView. After changing some data in the ObservableCollection I call the Rebind() method to visualize the changed data and this works fine, if I do this within the class the GridView is instanciated. 

The goal is to change the row data from the DetailsView. I pass an instance of the data grid ( I tried to pass an instance of the Grids parent class, also ) to the RowDetails-UserControl an call the Rebind() method after changing the data. This ends up with this COM-Error:

{System.Exception: Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zurückgegeben.
   bei MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   bei MS.Internal.XcpImports.Collection_Clear[T](PresentationFrameworkCollection`1 collection)
   bei System.Windows.PresentationFrameworkCollection`1.ClearImpl()
   bei System.Windows.PresentationFrameworkCollection`1.Clear()
   bei Telerik.Windows.Controls.GridView.GridViewBaseVirtualizingPanel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
   bei Telerik.Windows.Controls.GridView.GridViewBaseVirtualizingPanel.OnItemsChangedHandler(Object sender, ItemsChangedEventArgs args)
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.OnRefresh()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Refresh()
   bei Telerik.Windows.Controls.GridView.GridViewDataControl.ItemsSourceChanged(Boolean sourceChanged)
   bei Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)
   bei Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   bei System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   bei Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   bei Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs e)
   bei Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   bei System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   bei Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   bei Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
   bei Telerik.Windows.Data.QueryableCollectionView.RefreshInternal()
   bei Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
   bei Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args)
   bei Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
   bei Telerik.Windows.Data.QueryableCollectionView.Refresh()
   bei Telerik.Windows.Controls.DataControl.Rebind()
   bei PV.UI.Classes.Interactions.GET_SUPERVISED_POS_BY_AGENCYORGAMEMBER_ID.RebindData()
   bei PV.UI.Controls.PoSSupervisorRowDetail.CalculateDate(Object sender, SelectionChangedEventArgs e)}

Is using the Rebind() method the proper way for this scenario or should I use a completely different way?

Thanks for your help!

Jonas

4 Answers, 1 is accepted

Sort by
0
invDev
Top achievements
Rank 1
answered on 03 Mar 2011, 12:09 PM
Hello again,

since I know my problem is not really easy to understand, I will give you an overview of the whole scenario. Please take a look at the screenshot first. There are two datepickers in the RowDetails view. If one of them changes its date, the eventhandler calculates the difference between them. Afterwards, the DataObject the GridRow is based on gets refreshed and calling the Rebind() Method shows the correct colored dot in the first columns of the grid. As mentioned above this works fine, if the Refresh() Method is called from the same class in which the GirdView is located. 

Now, this is how I've build the code:

The RowDetailsTemplate of the Grid contains the UserControl with the datepickers:

<DataTemplate x:Key="PosSupervisorGridRow">
    <PVUIControls:PoSSupervisorRowDetail></PVUIControls:PoSSupervisorRowDetail>
</DataTemplate>

In this UserControl I implemented an EventHandler whicht reacts on the SelectionChanged event of the datepickers. The color of the dots is calculated in this method and I want to call the Rebind() method of the DataGrid after this calculations.

To get and manipulate the data object of the GridViewRow I use the DataContext property of the RowDetail UserControl. For getting a reference of the GridView I tried several approaches:

- Set a reference of the Grid in each data object.
- Declare a RadGridView member in the UserControl an set the value in the LoadingRowDetails handler of the GridView.
- Pass the GridViewRow from the GridViewRowDetailsEventArgs into the UserControl in the LoadingRowDetails handler.

Every call of the Rebind() method within the DetailsView UserControl leads to the COM exception described in the first post.
Calling this method from the class in which the GridView is defined works fine.

If there is a better pattern for such a scenario, please let me know. Otherwise, it would be great if you could give me a hint, why the Rebind() method is not working properly.

Thanks a lot for your help!

Jonas






0
Accepted
Rossen Hristov
Telerik team
answered on 03 Mar 2011, 01:12 PM
Hello invDev,

Can you try to call the Rebind method of the parent grid by using Dispatcher.BeginInvoke.

Also, does your business object class implement the INotifyPropertyChanged interface. In case it does, it might not be needed to call the Rebind method of the parent grid altogether.

I have attached a small sample project that does something similar, i.e. it changes a property of the master record from within its detail view. When you run the sample project and you enter a new name for the club from its row details -- it is automatically updated in the master grid's row. So maybe you don't even need to call Rebind after all.

In case none of these helps, could you please open a separate support ticket and attach a small dummy project that represents your exact architecture. We will take a look at it and see whether anything can be done.

Thanks in advance. We are looking forward to hearing from you.

All the best,
Ross
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
invDev
Top achievements
Rank 1
answered on 03 Mar 2011, 01:50 PM
Using the INotifyPropertyChanged interface instead of rebinding the whole DataSource is a very neat solution and works perfectly fine. I had it in mind, but never figured it out completely. This helps a lot!

Thanks for all your good work, Jonas
0
Rossen Hristov
Telerik team
answered on 03 Mar 2011, 01:56 PM
Hello invDev,

We are glad that this worked out for you.

The INotifyCollectionChanged and INotifyPropertyChanged interfaces are the basic building blocks of every Silverlight application and Rad Controls "understand" them very well.

In fact, you can't really achieve much if your collections and business objects do not implement these two interfaces.

Best wishes,
Ross
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
invDev
Top achievements
Rank 1
Answers by
invDev
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or