Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 158443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:40:57+00:00 2026-05-11T10:40:57+00:00

actually Im not getting problems with sorting a normal ListView.ItemsSource, my issue actually comes

  • 0

actually Im not getting problems with sorting a normal ListView.ItemsSource, my issue actually comes when I have a IGrouping List as ItemSource or SelectedItems, Im using the following snippet :

    private void Sort(string sortBy, ListSortDirection direction)     {         lastDirection = direction;         ICollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource);          dataView.SortDescriptions.Clear();         SortDescription sd = new SortDescription(sortBy, direction);         dataView.SortDescriptions.Add(sd);         dataView.Refresh();     } 

when sortBy = some ListView Column, direction = ascending, descending (depends last sorting)

so how can I set a ItemSource like the following : IList when T = myClass

Thanks in advance!

updated :

Modified the above snippet :

private void Sort(string sortBy, ListSortDirection direction) {     lastDirection = direction;     ICollectionView dataView;     if (this.Name.Equals('dlstPlantillas'))     {         List<Plantilla> newItemSource = new List<Plantilla>();         var source = this.ItemsSource;          foreach (var group in source)         {             System.Linq.IGrouping<string, Plantilla> groupCast = group as System.Linq.IGrouping<string, Plantilla>;             if (null == groupCast) return;             foreach (Plantilla item in groupCast)             {                 newItemSource.Add(item);             }         }          dataView = CollectionViewSource.GetDefaultView(newItemSource);     }     else     {         dataView = CollectionViewSource.GetDefaultView(this.ItemsSource);     }                dataView.SortDescriptions.Clear();     SortDescription sd = new SortDescription(sortBy, direction);     dataView.SortDescriptions.Add(sd);     dataView.Refresh(); } 

Actually Im getting this stack :

System.ObjectDisposedException was unhandled by user code     Message = 'Unable to access the deleted object. \ R \ nNombre object: 'It has a DataContext accessed after Dispose..''     Source = 'System.Data.Linq'     ObjectName = 'It has been a DataContext accessed after Dispose.'     Stacktrace:          in System.Data.Linq.DataQuery `1.System.Collections.IEnumerable.GetEnumerator ()          in SRIMedico.com.SortableListView.Sort (String Sort, ListSortDirection direction) in D: \ cs_InformeMedico \ app \ SortableListView.cs: line 219          in SRIMedico.com.SortableListView.GridViewColumnHeaderClickedHandler (Object sender, RoutedEventArgs e) in D: \ cs_InformeMedico \ app \ SortableListView.cs: line 163          in System.Windows.RoutedEventHandlerInfo.InvokeHandler (Object target, RoutedEventArgs routedEventArgs)          in System.Windows.EventRoute.InvokeHandlersImpl (Object source, RoutedEventArgs args, Boolean reRaised)          in System.Windows.UIElement.RaiseEventImpl (DependencyObject sender, RoutedEventArgs args)          in System.Windows.UIElement.RaiseEvent (RoutedEventArgs e)          in System.Windows.Controls.Primitives.ButtonBase.OnClick ()          in System.Windows.Controls.GridViewColumnHeader.ClickImplement ()          in System.Windows.Controls.GridViewColumnHeader.OnClick ()          in System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp (MouseButtonEventArgs e)          in System.Windows.Controls.GridViewColumnHeader.OnMouseLeftButtonUp (MouseButtonEventArgs e)          in System.Windows.UIElement.OnMouseLeftButtonUpThunk (Object sender, MouseButtonEventArgs e)          in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler (Delegate genericHandler, Object genericTarget)          in System.Windows.RoutedEventArgs.InvokeHandler (Delegate handler, Object target)          in System.Windows.RoutedEventHandlerInfo.InvokeHandler (Object target, RoutedEventArgs routedEventArgs)          in System.Windows.EventRoute.InvokeHandlersImpl (Object source, RoutedEventArgs args, Boolean reRaised)          in System.Windows.UIElement.ReRaiseEventAs (DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)          in System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent (DependencyObject sender, MouseButtonEventArgs e)          in System.Windows.UIElement.OnMouseUpThunk (Object sender, MouseButtonEventArgs e)          in System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler (Delegate genericHandler, Object genericTarget)          in System.Windows.RoutedEventArgs.InvokeHandler (Delegate handler, Object target)          in System.Windows.RoutedEventHandlerInfo.InvokeHandler (Object target, RoutedEventArgs routedEventArgs)          in System.Windows.EventRoute.InvokeHandlersImpl (Object source, RoutedEventArgs args, Boolean reRaised)          in System.Windows.UIElement.RaiseEventImpl (DependencyObject sender, RoutedEventArgs args)          in System.Windows.UIElement.RaiseEvent (RoutedEventArgs args, Boolean trusted)          in System.Windows.Input.InputManager.ProcessStagingArea ()          in System.Windows.Input.InputManager.ProcessInput (InputEventArgs input)          in System.Windows.Input.InputProviderSite.ReportInput (InputReport inputReport)          in System.Windows.Interop.HwndMouseInputProvider.ReportInput (IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 and Int32 wheel)          in System.Windows.Interop.HwndMouseInputProvider.FilterMessage (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)          in System.Windows.Interop.HwndSource.InputFilterMessage (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)          in MS.Win32.HwndWrapper.WndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)          in MS.Win32.HwndSubclass.DispatcherCallbackOperation (Object o)          in System.Windows.Threading.ExceptionWrapper.InternalRealCall (Delegate callback, Object args, Boolean isSingleParameter)          in System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)          in System.Windows.Threading.Dispatcher.WrappedInvoke (Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)          in System.Windows.Threading.Dispatcher.InvokeImpl (DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)          in System.Windows.Threading.Dispatcher.Invoke (DispatcherPriority priority, Delegate method, Object arg)          in MS.Win32.HwndSubclass.SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)          in MS.Win32.UnsafeNativeMethods.DispatchMessage (MSG & msg)          in System.Windows.Threading.Dispatcher.PushFrameImpl (DispatcherFrame frame)          in System.Windows.Threading.Dispatcher.PushFrame (DispatcherFrame frame)          in System.Windows.Window.ShowHelper (Object booleanBox)          in System.Windows.Window.Show ()          in System.Windows.Window.ShowDialog ()     InnerException: 

is so hard? :S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:40:57+00:00Added an answer on May 11, 2026 at 10:40 am

    Looking at the stack trace indicates that you’re using a LINQ-to-SQL query as your data source for the List Box. It appears that you then dispose the DataContext on which the query was made. When you do the Refresh() on the DataView it is trying to re-run the query, but fails because the DataContext is disposed.

    I quess what you need to do is capture the results of the query to a list before binding it to the ItemsControl. You can use the ToList() extension method to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It depends on how you issue it. If you just… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer Create a second target (duplicate the main one) for the… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer I tend to use has_many :through, but have you tried… May 11, 2026 at 11:44 pm

Related Questions

I'd like to implement a way to display a list of stored addresses sorted
I'm having real difficulty getting the eclipselink.join-fetch hint to work in glassfish. I have
Let me provide a little detail to explain what I'm trying to accomplish before
I'm having major problems getting Django working with my Apache configuration. I did not

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.