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

Exception during custom sorting 2010 Q2 SP2.

5 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 05 Oct 2010, 12:10 PM

Exception during custom sorting 2010 Q2 SP2.

Hi

2010 Q2 SP2.

 I have random exception when I want sort in grid.

 I do something wrong or there is bug in grid?

 In my scenario I do custom sorting:

 

 

private void radGridView1_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
{
        if (e.Column.Name == "Size")
        {
            SizeObject size1 = e.CellValue1 as SizeObject;
            SizeObject size2 = e.CellValue2 as SizeObject;
            if (size1.Size > size2.Size)
            { e.SortResult = 1; }
            else if (size1.Size < size2.Size)
            { e.SortResult = -1; }
            else
            { e.SortResult = 0; }
        }
        if (e.Column.SortOrder == RadSortOrder.Descending)
        { e.SortResult *= -1; }
    }
}

 

ArgumentException - Insufficient space in the target location to copy the information.

at System.Collections.Generic.LinkedList`1.CopyTo(T[] array, Int32 index)
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Telerik.WinControls.UI.GridViewSynchronizationService.AnalyzeQueue()
at Telerik.WinControls.UI.GridViewSynchronizationService.FlushEvents()
at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewEvent gridEvent)
at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewTemplate template, GridViewEvent eventData, Boolean postUI)
at Telerik.WinControls.UI.GridViewTemplate.DispatchEvent(GridViewEvent gridEvent, Boolean postUI)
at Telerik.WinControls.UI.GridViewTemplate.DispatchDataViewChangedEvent(Object sender, DataViewChangedEventArgs args)
at Telerik.WinControls.UI.GridViewTemplate.FireViewChangedEvent(Object sender, DataViewChangedEventArgs args)
at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(DataViewChangedEventArgs e)
at Telerik.WinControls.UI.GridViewTemplate.CollectionView_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Telerik.WinControls.Data.RadCollectionView`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at Telerik.WinControls.Data.RadDataView`1.RebuildData(Boolean notify)
at Telerik.WinControls.Data.RadDataView`1.RefreshOverride()
at Telerik.WinControls.Data.RadDataView`1.OnNotifyPropertyChanged(PropertyChangedEventArgs e)
at Telerik.WinControls.Data.RadCollectionView`1.OnNotifyPropertyChanged(String propertyName)
at Telerik.WinControls.Data.RadCollectionView`1.sortDescriptors_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Telerik.Collections.Generic.NotifyCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at Telerik.WinControls.UI.GridViewSortDescriptorCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at Telerik.Collections.Generic.NotifyCollection`1.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
at Telerik.Collections.Generic.NotifyCollection`1.InsertItem(Int32 index, T item)
at Telerik.WinControls.Data.SortDescriptorCollection.InsertItem(Int32 index, SortDescriptor item)
at Telerik.WinControls.UI.GridViewSortDescriptorCollection.InsertItem(Int32 index, SortDescriptor item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Telerik.WinControls.UI.GridViewColumn.Sort(RadSortOrder sortOrder, Boolean multiSortMode)
at Telerik.WinControls.UI.GridHeaderRowBehavior.OnMouseUp(MouseEventArgs e)
at Telerik.WinControls.UI.BaseGridBehavior.OnMouseUp(MouseEventArgs e)
at Telerik.WinControls.UI.RadGridView.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at Telerik.WinControls.RadControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Regards

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2010, 01:25 PM
Hello Raymond,

Please try the following example, everything is working as expected, please let me know if you are doing something different:

using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
 
    public partial class Form1 : Form
    {
        private RadGridView radGridView1 = new RadGridView();
 
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);
        }
 
        void Form1_Load(object sender, EventArgs e)
        {
            radGridView1.Dock = DockStyle.Fill;
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            this.Controls.Add(radGridView1);
            radGridView1.DataBindingComplete += new GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
            radGridView1.CustomSorting += new GridViewCustomSortingEventHandler(radGridView1_CustomSorting);
            radGridView1.EnableSorting = true;
 
            radGridView1.DataSource = new ProductsCollection(5000);
        }
 
        void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        {
            ((RadGridView)sender).Columns["Size"].CustomDataOperation = CustomDataOperation.Sorting;
        }
 
        private void radGridView1_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
        {
            if (e.Column.Name == "Size")
            {
                SizeObject size1 = e.CellValue1 as SizeObject;
                SizeObject size2 = e.CellValue2 as SizeObject;
                if (size1.Size > size2.Size)
                {
                    e.SortResult = 1;
                }
                else if (size1.Size < size2.Size)
                {
                    e.SortResult = -1;
                }
                else
                {
                    e.SortResult = 0;
                }
            }
 
            if (e.Column.SortOrder == RadSortOrder.Descending)
            {
                e.SortResult *= -1;
            }
        }
    }
 
    #region Helpers
 
    public class Product
    {
        public int Id
        {
            get;
            set;
        }
 
        public SizeObject Size
        {
            get;
            set;
        }
 
        public string Name
        {
            get;
            set;
        }
 
        public Product(int id, SizeObject size, string name)
        {
            this.Id = id;
            this.Size = size;
            this.Name = name;
        }
    }
 
    public class SizeObject
    {
        public int Id
        {
            get;
            set;
        }
 
        public int Size
        {
            get;
            set;
        }
 
        public SizeObject(int id, int size)
        {
            this.Id = id;
            this.Size = size;
        }
 
        public override string ToString()
        {
            return Size.ToString();
        }
    }
 
    public class ProductsCollection : BindingList<Product>
    {
        public ProductsCollection(int noItems)
        {
            for (int i = 0; i < noItems; i++)
            {
                this.Add(new Product(i, new SizeObject(i, i % 2 == 0 ? i + 100 : i), "Name" + i));
            }
        }
    }
 
    #endregion Helpers

Best Regards,
Emanuel Varga
0
Alexander
Telerik team
answered on 08 Oct 2010, 11:44 AM
Hello Raymond,

As illustrated by the Emanuel's example, the code snippet you use is not the reason for this issue itself. Since I am not able to reproduce the issue, I would kindly ask you to create a new support ticket and attach your project to it. This will allow me to assist you further.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Raymond
Top achievements
Rank 1
answered on 08 Oct 2010, 03:24 PM
I think I will prepare example with problem in next week...
0
Nikolay
Telerik team
answered on 18 Oct 2010, 04:45 PM
Hello Raymond,

Feel free to open a new support ticket and send us the sample project when it is ready.

Best wishes,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Raymond
Top achievements
Rank 1
answered on 19 Oct 2010, 07:46 AM

It is very random issue so it doesn`t hurt me so much.

When I finish more urgent issues in my app I will check this problem…

 

Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Alexander
Telerik team
Raymond
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or