Completed
Last Updated: 25 Nov 2016 08:51 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 24 Nov 2016 09:19
Category: GridView
Type: Bug Report
1
FIX. RadGridView - InvalidCastException when copying the entire row and a DateTime value is contained in a GridViewTextBoxColumn
To reproduce:

GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn("Col 1");
textBoxColumn1.FieldName = "col1";
radGridView1.MasterTemplate.Columns.Add(textBoxColumn1);
GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn("Col 2");
textBoxColumn2.FieldName = "col2";
textBoxColumn2.FormatString = "{0:d}"; 
radGridView1.MasterTemplate.Columns.Add(textBoxColumn2);
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

DataTable dt = new DataTable();
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(DateTime));
for (int i = 0; i < 10; i++)
{
    dt.Rows.Add("Item" + i, DateTime.Now.AddDays(i)); 
}
this.radGridView1.AutoGenerateColumns = false;
this.radGridView1.DataSource = dt;

Right click the row header cell and select Copy. The  following exception occurs although we don't have a GridViewDateTimeColumn : System.InvalidCastException was unhandled
  HResult=-2147467262
  Message=Unable to cast object of type 'Telerik.WinControls.UI.GridViewTextBoxColumn' to type 'Telerik.WinControls.UI.GridViewDateTimeColumn'.
  Source=Telerik.WinControls.GridView
  StackTrace:
       at Telerik.WinControls.UI.MasterGridViewTemplate.CopyRows(String format, Boolean cut, Boolean cutOperation, StringBuilder content)
       at Telerik.WinControls.UI.MasterGridViewTemplate.ProcessContent(String format, Boolean cut, Boolean cutOperation)
       at Telerik.WinControls.UI.MasterGridViewTemplate.CopyContent(Boolean cut)
       at Telerik.WinControls.UI.MasterGridViewTemplate.Copy()
       at Telerik.WinControls.UI.GridDataRowElement.copyItem_Click(Object sender, EventArgs e)
       at Telerik.WinControls.RadElement.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadMenuItem.OnClick(EventArgs e)
       at Telerik.WinControls.RadElement.DoClick(EventArgs e)
       at Telerik.WinControls.RadElement.RaiseBubbleEvent(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.RaiseBubbleEvent(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 Telerik.WinControls.UI.RadPopupControlBase.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.Run(Form mainForm)
       at _1075342CopyText.Program.Main() in d:\Projects\1075342CopyText_Binding\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Workaround: use a GridViewDateTimeColumn 
Attached Files:
0 comments