Home Forums WPF controls Xceed DataGrid for WPF Exception when sorting by added columns

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21948 |

    Hi

    In my application I have an DataGridControl with 5 columns. When the user clicks a button, another 5 columns are added to the control, using the grid.Columns.Add(column) method. These columns are specified in a resource in the XAML file and added in the code of the button handler.

    When the header of any of these new columns is clicked, I get the following exception:

    System.ArgumentNullException

    Value cannot be null.
    Parameter name: propertyName

    at System.ComponentModel.SortDescription..ctor(String propertyName, ListSortDirection direction)\r\n at Xceed.Wpf.DataGrid.DataGridControl.ApplyColumnSort(Column column, SortDirection sortDirection)\r\n at Xceed.Wpf.DataGrid.DataGridControl.ToggleColumnSort(Column column, ModifierKeys modifiers)\r\n at Xceed.Wpf.DataGrid.ColumnManagerCell.OnMouseLeftButtonUp(MouseButtonEventArgs e)\r\n at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)\r\n at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)\r\n at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)\r\n at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)\r\n at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)\r\n at System.Windows.UIElement.ReRaiseEventAs(RoutedEventArgs args, RoutedEvent newEvent)\r
    \n at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)\r\n at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)\r\n at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)\r\n at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)\r\n at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)\r\n at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)\r\n at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)\r\n at System.Windows.Input.InputManager.ProcessStagingArea()\r\n at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)\r\n at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)\r\n at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actio
    ns, Int32 x, Int32 y, Int32 wheel)\r\n at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)\r\n at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)\r\n at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)\r\n at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

    Imported from legacy forums. Posted by nmosafi (had 5401 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you set the value of the FieldName property on those columns?

    Imported from legacy forums. Posted by Pascal (had 353 views)

    User (Old forums)
    Member
    Post count: 23064

    Ahh that seems to have fixed it, thanks! What is the purpose of the field name anyway?

    Also how does the sorting work because one of my columns is bound to a Nullable<DateTime> and the sort appears to do nothing?

    Imported from legacy forums. Posted by nmosafi (had 296 views)

    User (Old forums)
    Member
    Post count: 23064

    In fact, the sorting doesn’t seem to be working at all, on any column! The order is seemingly random.

    Imported from legacy forums. Posted by nmosafi (had 372 views)

    User (Old forums)
    Member
    Post count: 23064

    Right so it seems that the FieldName is being used by the sort to do some reflection on properties…

    So before my fieldnames were just made up, now I have to make them the same as my DisplayMemberBinding… e.g

    <xcdg:Column FieldName=”Statistics.WhenLastPublished” Title=”Last Published” DisplayMemberBinding=”{Binding Path=Statistics.WhenLastPublished, Converter={StaticResource DateTimeConverter}}” Width=”100″ />

    Will this always work? What if I was binding to some ObjectDataProvider method, or had a multibinding with a converter etc?

    Actually it seems to me that the Xceed grid is just passing the FieldName property into the CollectionViewSource.SortDescriptions – can u confirm this is true?

    Thanks
    Neil

    Imported from legacy forums. Posted by nmosafi (had 325 views)

    User (Old forums)
    Member
    Post count: 23064

    This is exactly what we do (use the FieldName to construct a PropertySortDescription object).

    Sorting and Grouping features currently rely on the FieldName to work, but we are working on making the entire sorting/grouping infrastructure more flexible.

    Imported from legacy forums. Posted by Pascal (had 226 views)

    User (Old forums)
    Member
    Post count: 23064

    Cool!

    It would be good to update the docs as they currently say “Gets or sets the case-sensitive fieldname that uniquely identifies the column in the grid’s column collection.”

    Would be nice to know exactly how this FieldName is used by the grid.

    Cheers
    Neil

    Imported from legacy forums. Posted by nmosafi (had 265 views)

    User (Old forums)
    Member
    Post count: 23064

    Good point, I filed a request to our tech writer for that.

    Imported from legacy forums. Posted by Pascal (had 6750 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.