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

Can the RGV columns be deleted before unloaded event is fired?

3 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Veteran
Vladimir asked on 07 Sep 2020, 03:36 PM

We have our custom class for saving the grid configuration, i.e sorting/grouping/resizing/column order and we add Unloaded event on our grid like so:

            public static void Persistence(/*params here*/)

                  grid.Unloaded += (sender, args) =>
                  {
                         var data = GenerateGridSettings(grid, whatToSave, column => column.UniqueName);
                         if (data != null)
                              // save settings goes here
                   };

             }

Although this looks good and I as developer and the QA team do not get error messages, our customers get error messages, specifically "Object was not set to an instance of an object". The error output is this:

    2020/09/03 09:36:17.259 29 - 17832 Client.Global.Dispatcher FATAL Object reference not set to an instance of an object.
       at Controls.RadGridSupport.<>c.<Persistence>b__26_4(GridViewColumn column)
       at Controls.RadGridSupport.GenerateGridSettings(RadGridView rgv, RadGridSettingSelection whatToSave, Func`2 mapColumnToName)
       at Controls.RadGridSupport.<>c__DisplayClass26_0.<Persistence>b__1(Object sender, RoutedEventArgs args)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
       at System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)
       at MS.Internal.LoadedOrUnloadedOperation.DoWork()
       at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

 

As if the column in the lambda expression "column => column.UniqueName" gets deleted at some point before unloaded event.

 

Is this possible? Can the column be deleted before the unloaded event?


3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 10 Sep 2020, 08:45 AM

Hi Vladimir,

Thank you for the provided stack trace.

I'm uncertain as to why this exception is observed in this case, and only on some machines, but what I can recommend trying is to use the DataMemberBinding.Path.Path instead of UniqueName to get ahold of the name of the bound property.

To directly answer your question, it is possible that the columns are removed before the Unloaded event is fired, but this depends on many variables and I cannot say for certain whether this is the case in this particular scenario without being able to replicate the exception at my end.

If the approach suggested earlier does not resolve your issue, could you please try isolating the exception in a small sample project and send it over so that I can further investigate. You can upload the project to a storage provided of your choice or create a new support ticket for the purpose.

Please let me know how this goes. I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Vladimir
Top achievements
Rank 1
Veteran
answered on 10 Sep 2020, 09:30 AM

We have composite columns with multiple bound fields.

For example I have a property

        private string _DetailsColumn;
        public string DetailsColumn
        {
            get { return _DetailsColumn; }
            set
            {
                _DetailsColumn = value;
                OnPropertyChanged(() => DetailsColumn);
            }
        }

Which I bind to

<tk:GridViewDataColumn
                                HeaderCellStyle="{StaticResource MyGridViewHeaderCell}"
                                IsSortable="False"
                                MinWidth="250"
                                DataMemberBinding="{Binding DetailsColumn}"
                                UniqueName="DetailsColumn"
                                Header="Details"
                                IsReorderable="False"
                                CellStyle="{StaticResource MyGridViewCell}"
                                CellTemplateSelector="{StaticResource CellTemplateSelector}"
                                CellEditTemplate="{StaticResource EditTemplate}"/>

I though these composite columns might not have a value so in my view model constructor i just added

         public MyViewModel()

         {

                  // other code

                  DetailsColumn = "DetailsColumn";

         }

1. Should I have both DataMemberBinding and CellTemplate? But everything works as expected though I have both.

2. Should the UniqueName be the same as the bound field, but again everything works as expected?

3. Could the bound field be problem here, having null before unloading the RadGridView?

4. What are the cases when the column gets deleted before unloading the grid view?

 

Changing from UniqueName to DataMemberBinding.Path.Path is not an option here since we have multiple windows with grid views that use the same support class and time is short to test all those if the work properly.

0
Dilyan Traykov
Telerik team
answered on 15 Sep 2020, 08:54 AM

Hello Vladimir,

Thank you for the clarifications and code snippets.

I will try to answer your inquiries in the order you've defined them:

1. You need to have the DataMemberBinding property defined to support data operations such as filtering, sorting and grouping. Alternatively, you can use the Filter/Sort/GroupMemberPath properties to point the column to the property which is responsible for the respective operation.

2. You should avoid setting the UniqueName property explicitly as this is normally determined by the DataMemberBinding property and is dependant on it.

3. Generally speaking, setting the bound property to null should not lead to the column being cleared. This can be the case if the column is explicitly removed from the control's Columns collection.

4. I'm afraid I cannot think of a specific case when the columns will be explicitly removed from the control before it is unloaded, but theoretically, this is possible. The more likely cause for this exception, however, I believe is that for some reason the UniqueName property is cleared. I cannot, however, pinpoint an exact cause for this without being able to replicate the exception at my end. Can you please specify whether you explicitly set the UniqueName property somewhere in your application and if so - whether this can be avoided?

Finally, just to clarify - you will not find it possible to change the parameter being passed to the GenerateGridSettings method from UniqueName to DataMemberBinding.Path.Path?

var data = GenerateGridSettings(grid, whatToSave, column => column.DataMemberBinding.Path.Path);
If this would not be possible, please also share the code behind the GenerateGridSettings method and the place where the exception occurs so that I can further investigate or ideally - send over a small sample project which demonstrates the exception so I have the best chance of providing a viable solution.

Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Vladimir
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Vladimir
Top achievements
Rank 1
Veteran
Share this question
or