Error calling BestFitColumns

36 posts, 0 answers
  1. Joel Kraft
    Joel Kraft avatar
    87 posts
    Member since:
    Jan 2004

    Posted 28 Feb 2011 Link to this post

    Whenever I've been getting this, it's because I have the MinWidth and MaxWidth on a column set to the same value (same issue Marc-Andre had). I can confirm that the code sample posted on 12/27/2010 does not fix the issue I'm having. Let me know if you need me to put something together to reproduce the issue (it'll take a while to tear the affected parts out of my product, but I can do it if you can't reproduce the behavior).

  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 02 Mar 2011 Link to this post

    Hi Joel,

    Unfortunately, I am not able to assist you following the supplied information. Could you open a support ticket with an attached project where the issue occurs?

    Thank you for your cooperation.

    All the best,
    Svett
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for WinForms is Visual Studio 2017 Ready
  4. John
    John avatar
    21 posts
    Member since:
    Sep 2013

    Posted 27 Jan 2015 Link to this post

    Hi, I recently upgraded from 2014.1  to 2014.3 *.1202.20) and now I am getting an error when calling BestFitColumns(BestFitColumnMode.DisplayedCells). The full error message is below.  The inner exception is

           InnerException: System.NotSupportedException
                HResult=-2146233067
                Message='RadGridDateTimeConverter' is unable to convert 'System.String' to 'System.DateTime'.

    Any Ideas?  This worked with the earlier version.  
    I am pivoting a Text Column and some of the dates may be null.

    Thanks,

    John


    Full error msg:

    System.Int32
    A first chance exception of type 'System.FormatException' occurred in Telerik.WinControls.GridView.dll
    Error 13: Converter cannot process the value with this parameters.

    System.Reflection.TargetInvocationException was unhandled
      HResult=-2146232828
      Message=Exception has been thrown by the target of an invocation.
      Source=mscorlib
      StackTrace:
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, 

    Boolean constructor)
           at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, 

    Object[] arguments)
           at System.Delegate.DynamicInvokeImpl(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, 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.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
           at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
           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.IMsoComponent

    Manager.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(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] 

    commandLine)
           at CryoInv.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.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: System.FormatException
           HResult=-2146233033
           Message=Converter cannot process the value with this parameters.
           Source=Telerik.WinControls.GridView
           StackTrace:
                at Telerik.WinControls.UI.RadDataConverter.ThrowFormatException(Exception ex, String 

    message)
                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.GridCellElement.SetContent()
                at Telerik.WinControls.UI.GridVirtualizedCellElement.OnPropertyChanged

    (RadPropertyChangedEventArgs e)
                at Telerik.WinControls.RadObject.RaisePropertyNotifications(RadPropertyValue propVal, Object 

    oldValue, Object newValue, ValueSource oldSource)
                at Telerik.WinControls.RadObject.ResetValueCore(RadPropertyValue propVal, ValueResetFlags 

    flags)
                at Telerik.WinControls.RadObject.UnbindProperty(RadProperty boundProperty)
                at Telerik.WinControls.UI.GridDataCellElement.UnbindColumnProperties()
                at Telerik.WinControls.UI.GridVirtualizedCellElement.Detach()
                at Telerik.WinControls.UI.GridDataCellElement.Detach()
                at Telerik.WinControls.UI.GridVirtualizedRowElement.DetachCells()
                at Telerik.WinControls.UI.GridDataRowElement.Detach()
                at Telerik.WinControls.UI.BaseVirtualizedContainer`1.UpdateElement(Int32 position, T data)
                at Telerik.WinControls.UI.ScrollableRowsContainerElement.UpdateElement(Int32 position, 

    GridViewRowInfo data)
                at Telerik.WinControls.UI.BaseVirtualizedContainer`1.MeasureElements()
                at Telerik.WinControls.UI.BaseVirtualizedContainer`1.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.UI.ScrollableRowsContainerElement.MeasureOverride(SizeF 

    availableSize)
                at Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.UI.RowsContainerElement.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.UI.ScrollViewElement`1.MeasureViewElement(SizeF availableSize)
                at Telerik.WinControls.UI.ScrollViewElement`1.MeasureView(SizeF availableSize)
                at Telerik.WinControls.UI.ScrollViewElement`1.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.UI.GridTableElement.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.Layouts.DockLayoutPanel.MeasureOverride(SizeF constraint)
                at Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.UI.LightVisualElement.MeasureElements(SizeF availableSize, SizeF 

    clientSize, Padding borderThickness)
                at Telerik.WinControls.UI.LightVisualElement.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.RootRadElement.MeasureOverride(SizeF availableSize)
                at Telerik.WinControls.RootRadElement.MeasureCore(SizeF availableSize)
                at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
                at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
                at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayoutCallback(ILayoutManager 

    manager)
           InnerException: System.NotSupportedException
                HResult=-2146233067
                Message='RadGridDateTimeConverter' is unable to convert 'System.String' to 

    'System.DateTime'.
                Source=System
                StackTrace:
                     at System.ComponentModel.TypeConverter.GetConvertToException(Object value, Type 

    destinationType)
                     at System.ComponentModel.TypeConverter.ConvertTo(ITypeDescriptorContext context, 

    CultureInfo culture, Object value, Type destinationType)
                     at System.ComponentModel.DateTimeConverter.ConvertTo(ITypeDescriptorContext context, 

    CultureInfo culture, Object value, Type destinationType)
                     at Telerik.WinControls.UI.RadGridDateTimeConverter.ConvertTo(ITypeDescriptorContext 

    context, CultureInfo culture, Object value, Type destinationType)
                     at Telerik.WinControls.UI.RadDataConverter.FormatCore(Object value, Type targetType, 

    CultureInfo cultureInfo, IDataConversionInfoProvider dataColumn, Boolean checkForNullValue)
                     at Telerik.WinControls.UI.RadDataConverter.FormatNullValue(Object value, Type 

    targetType, CultureInfo cultureInfo, TypeConverter dataTypeConverter, IDataConversionInfoProvider 

    column, Object& result)
                     at Telerik.WinControls.UI.RadDataConverter.FormatCore(Object value, Type targetType, 

    CultureInfo cultureInfo, IDataConversionInfoProvider dataColumn, Boolean checkForNullValue)
                     at Telerik.WinControls.UI.RadDataConverter.Format(Object value, Type targetType, 

    Boolean coerceNullValue, IDataConversionInfoProvider converstionInfoProvider)
                InnerException: 







  5. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 30 Jan 2015 Link to this post

    Hello John,

    Thank you for writing.

    I created a sample project and tried to reproduce the exception which you describe but to no avail. In my example the BestFitColumns method is called on a Click event of a button, I have also tried calling it just after binding the grid to the data source, in both cases the result is the same - an exception is not thrown. Please see my example below:
    public Form1()
    {
        InitializeComponent();
     
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Age", typeof(int));
        dt.Columns.Add("Date", typeof(string));
     
        for (int i = 0; i < 50; i++)
        {
            if (i % 2 == 0)
            {
                dt.Rows.Add("Name " + i, 20 + i, DateTime.Now.AddDays(i).ToLongDateString());
            }
            else
            {
                dt.Rows.Add("Name " + i, 20 + i, null);
            }
        }
     
        this.radGridView1.DataSource = dt;
        this.radGridView1.Columns.Remove("Date");
        GridViewDateTimeColumn dateTimeColumn = new GridViewDateTimeColumn("Date");
        dateTimeColumn.FieldName = "Date";
        dateTimeColumn.FormatString = "{0:D}";
        this.radGridView1.Columns.Add(dateTimeColumn);
        
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radGridView1.BestFitColumns(BestFitColumnMode.DisplayedCells);
    }

    Could you please share more details of your particular scenario? Feel free to modify my example so that it reproduces the exception. We would be happy to further investigate and quickly provide you with a working solution.

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Zohreh
    Zohreh avatar
    3 posts
    Member since:
    May 2016

    Posted 05 Oct in reply to Hristo Link to this post

    Hi Hristo,

    If you specify the DataType property to typeof(DateTime) on the date column, you will get the error even when trying to filter column.

     

    Cheers

  7. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 05 Oct Link to this post

    Hello Zohreh,

    Thank you for writing.

    The sample project as per my old snippet is still running fine on my end. Can you please open up a support ticket and send us your project reproducing the exception?

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready