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

WPF GridView Sorting issue

1 Answer 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pawan
Top achievements
Rank 1
Pawan asked on 16 Oct 2013, 05:17 PM
Hi,
We are creating columns dynamically. There are a few datetime columns where we set the datatype as DateTime and CellEditTemplate as below.

 dataColumn.DataType = (typeof(DateTime?));
            dataColumn.DataFormatString = "{0:dd-MMM-yyyy}";
            dataColumn.TextAlignment = TextAlignment.Right;
            dataColumn.CellEditTemplate = GetDatePickerTemplate(dataColumn);
        }

        private static DataTemplate GetDatePickerTemplate(GridViewDataColumn column)
        {
            var fef = new FrameworkElementFactory(typeof(FormatedRadDatePicker));
          ................

The issue is when you sort the grid with this datetime column and try to edit any value in this column the application crashes with below error:

 Dispatcher UnHandled Exception: System.ArgumentException: Object must be of type DateTime.
   at System.DateTime.CompareTo(Object value)
   at Telerik.Windows.Data.FunctionComparer.Compare(Object x, Object y)
   at Telerik.Windows.Data.ListExtensions.BinarySearch[T](IList`1 items, T value, Func`3 compareFunc)
   at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RefreshAlternation(GridViewDataControl parentGrid, GridViewRow gridViewRow, Object dataItem)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RealizeRows(Int32 startIndex, Int32 endIndex, Double& verticalOffset, HashSet`1& realizedRows)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.MeasureOverride(Size availableSize)
   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)...........


To me it looks like after the cell edit is over grid tries to put the newly edited data to its rightful place based on sortdescriptor. Probably it fetches the data from DateTimeTextProperty as string type and is not able to compare with DateTime values of other cells....

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 17 Oct 2013, 07:09 AM
Hi,

If you set the DataType manually you have to be sure that it is the correct DataType. In your case you have assigned a Nullable<DateTime> as the DataType which is fine.

You have to make sure that your editor is producing DateTime? values and not strings. From the code you have pasted I cannot see what your custom editor does and how you have bound it and what values it produces.

Only you can debug your DataMemberBinding and see what values are flowing into it when the user edits a cell.

Regards,
Rossen Hristov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Pawan
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or