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

DateTimeOffset

2 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deborah
Top achievements
Rank 1
Deborah asked on 03 Oct 2011, 04:04 PM
We recently changed all of our DateTime fields to DateTimeOffset. Now when we display one of the dates in a GridView, we get:

{"Converter can't convert"}

Is there something else we have to do to support DateTimeOffset in the grid?

Here is the detailed exception:

System.FormatException was unhandled
  Message=Converter can't convert
  Source=Telerik.WinControls.GridView
  StackTrace:
       at Telerik.WinControls.UI.RadDataConverter.ThrowFormatException(Exception ex, String message)
       at Telerik.WinControls.UI.RadDataConverter.ThrowFormatException(Exception ex)
       at Telerik.WinControls.UI.RadDataConverter.Format(Object value, Type targetType, Boolean coerceNullValue, IDataConversionInfoProvider converstionInfoProvider)
       at Telerik.WinControls.UI.GridDataCellElement.ApplyFormatString(Object value)
       at Telerik.WinControls.UI.GridDateTimeCellElement.ApplyFormatString(Object value)
       at Telerik.WinControls.UI.GridCellElement.SetContentCore(Object value)
       at Telerik.WinControls.UI.GridDataCellElement.SetContent()
       at Telerik.WinControls.UI.GridRowElement.UpdateContent()
       at Telerik.WinControls.UI.GridTableElement.UpdateCellContent(GridViewRowInfo rowInfo)
       at Telerik.WinControls.UI.GridTableElement.UpdateWhenItemChanged(DataViewChangedEventArgs args)
       at Telerik.WinControls.UI.GridTableElement.UpdateViewCore(Object sender, DataViewChangedEventArgs args)
       at Telerik.WinControls.UI.GridTableElement.UpdateView(Object sender, DataViewChangedEventArgs args)
       at Telerik.WinControls.UI.GridTableElement.ProcessTemplateEvent(GridViewEvent eventData)
       at Telerik.WinControls.UI.GridTableElement.Telerik.WinControls.UI.IGridViewEventListener.ProcessEvent(GridViewEvent eventData)
       at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessCollection(GridViewEvent gridEvent, PriorityWeakReferenceList list, GridEventProcessMode processMode)
       at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessEvent(GridViewEvent gridEvent)
       at Telerik.WinControls.UI.GridViewSynchronizationService.NotifyListeners(GridViewEvent gridEvent)
       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.OnViewChanged(Object sender, 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.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
       at Telerik.WinControls.Data.RadCollectionView`1.source_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.RadListSource`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.RadListSource`1.ChangeItem(Int32 index, TDataItem item, String propertyName)
       at Telerik.WinControls.Data.RadListSource`1.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
       at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.BindingSource.ListItem_PropertyChanged(Object sender, EventArgs e)
       at System.ComponentModel.PropertyDescriptor.OnValueChanged(Object component, EventArgs e)
       at System.ComponentModel.ReflectPropertyDescriptor.OnValueChanged(Object component, EventArgs e)
       at System.ComponentModel.ReflectPropertyDescriptor.OnINotifyPropertyChanged(Object component, PropertyChangedEventArgs e)
       at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
       at SCStar.BL.BOBase.NotifyPropertyChanged(String propertyName) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.BL\BoBase.vb:line 356
       at SCStar.BL.BOBase.SetEntityState(Nullable`1 newEntityState, String propertyName) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.BL\BoBase.vb:line 731
       at SCStar.BL.OnSite.AgreementDiscount.set_DiscountBeginDate(Nullable`1 value) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.BL\Site\AgreementDiscount.vb:line 183
       at SCStar.BL.OnSite.AgreementDiscounts.SetDiscountData(Agreement currentAgreementInstance, DateTimeOffset CurrentSiteDateTimeWithOffset, Nullable`1 isMoveIn) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.BL\Site\AgreementDiscounts.vb:line 430
       at SCStar.PaymentDiscountWin.SetDiscountData(AgreementDiscount updatedAgreementDiscountInstance) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.Win\PaymentDiscountWin.vb:line 476
       at SCStar.PaymentDiscountWin.PaymentDiscountGridView_CellEndEdit(Object sender, GridViewCellEventArgs e) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.Win\PaymentDiscountWin.vb:line 161
       at Telerik.WinControls.UI.RadGridView.OnCellEndEdit(Object sender, GridViewCellEventArgs e)
       at Telerik.WinControls.UI.EventDispatcher.RaiseEvent[T](Object eventKey, Object sender, T args)
       at Telerik.WinControls.UI.GridViewEditManager.EndEditCore(Boolean validate, Boolean cancel)
       at Telerik.WinControls.UI.GridViewEditManager.EndEdit()
       at Telerik.WinControls.UI.GridRowBehavior.ValidateOnUserInput(MouseEventArgs e)
       at Telerik.WinControls.UI.GridRowBehavior.OnMouseDown(MouseEventArgs e)
       at Telerik.WinControls.UI.BaseGridBehavior.OnMouseDown(MouseEventArgs e)
       at Telerik.WinControls.UI.RadGridView.OnMouseDown(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseDown(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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.Form.ShowDialog()
       at SCStar.UIController.DisplayDiscountDialog() in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.Win\UIController.vb:line 1483
       at SCStar.PaymentControl.EditDiscounts() in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.Win\PaymentControl.vb:line 1257
       at SCStar.PaymentControl.DiscountButton_Click(Object sender, EventArgs e) in C:\Users\Deb\Clients\SpaceControl\SCStar\SCStarApplication\SCStar.Win\PaymentControl.vb:line 294
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at Telerik.WinControls.RadControl.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButtonBase.ButtonElement_Click(Object sender, EventArgs e)
       at Telerik.WinControls.RadItem.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
       at Telerik.WinControls.RadItem.DoClick(EventArgs e)
       at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
       at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
       at Telerik.WinControls.RadControl.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at SCStar.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

2 Answers, 1 is accepted

Sort by
0
Deborah
Top achievements
Rank 1
answered on 03 Oct 2011, 05:07 PM
OK, we figured this out.

Since we changed from DateTime to DateTimeOffset after all of the UI was built, the grid still had the column defined as Nullable(of Date) in the designer file. As soon as we changed that from Date to DateTimeOffset, all was well.

0
Peter
Telerik team
answered on 06 Oct 2011, 02:11 PM
Hi Deborah,

Indeed, if your column is filled with data of type DateTimeOffset and the data type set for the column at design-time is Nullable(Of Date) it is normal to get that exception, since both types should be the same. You have correctly found the reason for the observed behavior - a serialized code line that defines the wrong data type for your column. I am glad that the issue is now resolved. Your experience might help other developers as well.

If you have additional questions, feel free to contact us.

Best wishes,
Peter
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Deborah
Top achievements
Rank 1
Answers by
Deborah
Top achievements
Rank 1
Peter
Telerik team
Share this question
or