Hi,
When sorting dateTime columns with ocassional null values I'm getting an exception:
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at Syncfusion.WinForms.DataGrid.SfDataGrid.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
at Interop.User32.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WBTDane.Program.Main() in C:\My_Projects\Other\WBTDane\WBTDane\Program.cs:line 25
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidOperationException: Failed to compare two elements in the array.
Inner Exception 2:
ArgumentException: Object must be of type DateTime.
--------------------------------------------
This is how I load data to DataGrid:
DataTable DT_startListsReadData = await ReadStartListsReadData();
var dynamicCollection = new ObservableCollection();
foreach (DataRow row in Globals.DT_startListsReadData.Rows)
{
ExpandoObject expandoObject = new();
dynamicCollection.Add(expandoObject);
foreach (DataColumn column in Globals.DT_startListsReadData.Columns)
{
var dictionary = ((IDictionary)expandoObject);
dictionary[column.ColumnName] = row[column];
}
}
DynamicOrders = dynamicCollection;
SfDataGridStartLists.DataSource = DynamicOrders;
Hi Leszek,
We are validating the reported issue. We will validate and update you with more details on March 17, 2022.
Regards,
Sampath Narayanan.S
Hi Leszek,
We are able to replicate the reported issue. We are currently validating the reported issue. We will validate and update you with more details on March 21, 2022.
Regards,
Sampath Narayanan.S
Hi Leszek,
We have checked the reported issue and found that we cannot use DBNull for the record in DataTable with the ExpandoObject(Without ExpandoObject sorting works fine when you directly use DataTable as DataSource). Please provide the details about why you are using the ExpandoObject and more details about your scenario. It will be more helpful for us to check the possibilities to achieve the requirement.
Regards,
Sampath Narayanan.S
Hi,
I have been using ExpandoObject object because DataTime columns from DataTable did not show time stamp in the grid. ExpandoObject example code I've found in Synfcusion documentation was showing correct data format including time stamp however with mentioned error when sorting.
Anyway, I've solved the problem formating DT columns on database side.
Thanks.
Hi Leszek,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this.
Regards,
Dhanasekar M.