Hi,
I have a very basic example where I bind a data grid to an IList<Country> Nations {get; set;} property.The Country class has two collections as properties:IList<City> Cities { get; set;}IList<Town> Towns { get; set;}.
I naturally get a nested grid ofCountry1+Cities+TownsCountry2+Cities+Towns
When I drag a collapsed Cities, or Towns row, I immediately get a null reference exception:
System.IndexOutOfRangeException:Index was outside the bounds of the array. Stack Trace:
at Infragistics.Windows.DataPresenter.DataPresenterBase.RecordSelectionEnumerator.GetNextSiblingRecord(Int32 levelIndex, Boolean& retry) at Infragistics.Windows.DataPresenter.DataPresenterBase.RecordSelectionEnumerator.GetNextSiblingRecord(Int32 levelIndex, Boolean& retry) at Infragistics.Windows.DataPresenter.DataPresenterBase.RecordSelectionEnumerator.GetNextSiblingRecord(Int32 levelIndex, Boolean& retry) at Infragistics.Windows.DataPresenter.DataPresenterBase.RecordSelectionEnumerator.MoveNext() at Infragistics.Windows.DataPresenter.DataPresenterBase.GetRecordsForSelection(Boolean select, RangeSelectionEvaluator evaluator) at Infragistics.Windows.DataPresenter.DataPresenterBase.CalculateSelectionRange(Record record, SelectedItemHolder newSelection, Boolean clearExistingSelection, Boolean select) at Infragistics.Windows.DataPresenter.DataPresenterBase.CalculateNewSelectionRange(ISelectableItem item, Boolean clearExistingSelection, Boolean select) at Infragistics.Windows.DataPresenter.DataPresenterBase.InternalSelectRange(ISelectableItem item, Boolean clearExistingSelection, Boolean select) at Infragistics.Windows.DataPresenter.DataPresenterBase.Infragistics.Windows.Selection.ISelectionHost.SelectRange(ISelectableItem item, Boolean clearExistingSelection) at Infragistics.Windows.Selection.SelectionStrategyExtended.OnMouseMove(ISelectableItem item, MouseEventArgs e) at Infragistics.Windows.Selection.SelectionController.OnMouseMove(MouseEventArgs e) at Infragistics.Windows.Controls.IGControlBase.OnMouseMove(MouseEventArgs e) at Infragistics.Windows.DataPresenter.DataPresenterBase.OnMouseMove(MouseEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)---------------------------------------------------------------------------------------------------------------
Hello,
Thank you for posting to IG forums!
Here I have attached a sample project representing how drag and drop functionality could be used for changing record’s position in hierarchical XamDataGrid. Could you please run the project on your side and let me know whether you get the same error? What is the specific version of Infragistics assemblies you are using? Thank you.
Hi Maria,
Thank you for the example, however the issue is in a different scenario, and a much simpler one. I have modified your example and was able to repro the exception:
Using v13.1
Source:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:igDP="http://infragistics.com/DataPresenter"> DataSource="{Binding}"/>
using System.Windows;using System.Collections.ObjectModel;
namespace DragDropRecordsInHierarchy{ /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent();
Data = new ObservableCollection { new Parent { ID = 1, Name = "Parent 1", Children1 = new ObservableCollection { new Child { Age = 15, Name = "Child 1", ParentName = "Parnet 1" }, new Child { Age = 11, Name = "Child 2", ParentName = "Parnet 1" }, new Child { Age = 2, Name = "Child 3", ParentName = "Parnet 1" }, },
Children2 = new ObservableCollection { new Child { Age = 15, Name = "Child 1", ParentName = "Parnet 1" }, new Child { Age = 11, Name = "Child 2", ParentName = "Parnet 1" }, new Child { Age = 2, Name = "Child 3", ParentName = "Parnet 1" }, } }, new Parent { ID = 2, Name = "Parent 2", Children1 = new ObservableCollection { new Child { Age = 7, Name = "Child 1", ParentName = "Parnet 2" }, new Child { Age = 1, Name = "Child 2", ParentName = "Parnet 2" }, new Child { Age = 4, Name = "Child 3", ParentName = "Parnet 2" }, },
Children2 = new ObservableCollection { new Child { Age = 15, Name = "Child 1", ParentName = "Parnet 1" }, new Child { Age = 11, Name = "Child 2", ParentName = "Parnet 1" }, new Child { Age = 2, Name = "Child 3", ParentName = "Parnet 1" }, } }, new Parent { ID = 3, Name = "Parent 3", Children1 = new ObservableCollection { new Child { Age = 5, Name = "Child 1", ParentName = "Parnet 3" }, new Child { Age = 17, Name = "Child 2", ParentName = "Parnet 3" }, new Child { Age = 18, Name = "Child 3", ParentName = "Parnet 3" }, },
Children2 = new ObservableCollection { new Child { Age = 15, Name = "Child 1", ParentName = "Parnet 1" }, new Child { Age = 11, Name = "Child 2", ParentName = "Parnet 1" }, new Child { Age = 2, Name = "Child 3", ParentName = "Parnet 1" }, } } };
DataContext = Data; }
public ObservableCollection Data { get; set; } }
public class Parent { public int ID { get; set; } public string Name { get; set; } public ObservableCollection Children1 { get; set; } public ObservableCollection Children2 { get; set; } }
public class Child { public string Name { get; set; } public int Age { get; set; } public string ParentName { get; set; } }}
The key is the second Child collection.
When you launch the app, and drag either the collapsed Child1, or Child2 headers, a null ref exception is thrown.
I am just checking your progress on the issue.
If you require any further assistance on the matter, please do not hesitate to ask.
I have tested this behavior with the attached project (DragDropRecordsInHierarchy(2).zip) where DataSource is changed with the one provided by you in your previous post. I have also modified the drag and drop functionality so that a check for the Children1 and Children2 is added. If the ExpandableFieldRecord name is Children1, Children1 collection is set as drag source and drop target. This will allow the user to drag and drop items within Children1 or Children2 collection. On the other hand, if the user tries to drag and drop the Children1 or Children2 ExpandableFieldRecord, no action would be taken.
Would you please run the attached project and let me know if the issue appears on your side when you try to drag and drop Children1 or Children2. If it is, would yo tell me what is the specific version you are using so I make sure that I am testing this with the same? Would you please modify the project, if the issue is not reproducible and I will look further into it? Thank you.
It occurs almost imediately after starting the drag operation, but before the mouse is released for the drop.
Please run the example, and you should be able to repro it easily.
If this is by design, I think it should be made safe and not do anything, as the user is providing a base case scenario and might nave never intended for drag/drop to work for that specific scenario.
When property of type ObservableCollection<Child> is added to the Parent class, the XamDataGrid will display it in ExpandableFieldRecordPresenter. This means that the drag and drop functionality should be changed so that the source and the target correspond to these elements. In the sample I have attached before the drag and drop works for datarecords only. You have mentioned that this error occurs when you drag the Child1 or Child2. Does the error occur when you drop the item or when you start dragging it? If it occurs after the item is dropped, probably the drag collection and the drop collection are not defined correctly. Here is a modified code snippet that allows the user to drag and drop the records under Children1:
Child drag = ((e.DragSource as ContentPresenter).DataContext as DataRecord).DataItem as Child;
Child drop = ((e.DropTarget as ContentPresenter).DataContext as DataRecord).DataItem as Child;
ObservableCollection<Child> parentDragCollection = (((e.DragSource as ContentPresenter).DataContext as DataRecord).ParentDataRecord.DataItem as Parent).Children1;
ObservableCollection<Child> parentDropCollection = (((e.DropTarget as ContentPresenter).DataContext as DataRecord).ParentDataRecord.DataItem as Parent).Children1;
int dropIndex = parentDropCollection.IndexOf(drop);
parentDragCollection.Remove(drag);
parentDropCollection.Insert(dropIndex, drag);
Similar functionality should be added if the user drag and drop records in Children2.
Please feel free to let me know if it helps you.