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

Error calling BestFitColumns

35 Answers 463 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bradley Schultz
Top achievements
Rank 1
Bradley Schultz asked on 17 Dec 2010, 08:55 PM
Since upgrading to Q3 SP1 I'm getting an error trying to use the BestFitColumns method on the GridView. What worked great on Q3 is now giving me an ArgumentOutOfRange exception.

Error Message is "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Stack trace is as follows:
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Telerik.WinControls.UI.StretchColumnLayoutHelper.ResizeColumn(Int32 delta)
   at Telerik.WinControls.UI.TableViewRowLayout.ResizeColumn(Int32 delta)
   at Telerik.WinControls.UI.TableViewRowLayout.StretchColumn(GridViewColumn column, Int32 desiredWidth)
   at Telerik.WinControls.UI.BestFitHelper.SetColumnWidth(GridViewColumn column, Single desiredWidth)
   at Telerik.WinControls.UI.BestFitHelper.BestFitColumnsCore()
   at Telerik.WinControls.UI.BestFitHelper.ProcessRequests()
   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.FireViewChangedEvent(Object sender, DataViewChangedEventArgs args)
   at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
   at Telerik.WinControls.UI.GridViewTemplate.BestFitColumns()
   at HBS.Scanesthesia.WinForms.MainForm.SelectedPageChanged(Object sender, EventArgs e) in C:\Users\bschultz\Documents\Visual Studio 2010\Projects\Scanesthesia\HBS.Scanesthesia.Forms\MainForm.cs:line 267
   at HBS.Scanesthesia.WinForms.MainForm.ShownForm(Object sender, EventArgs e) in C:\Users\bschultz\Documents\Visual Studio 2010\Projects\Scanesthesia\HBS.Scanesthesia.Forms\MainForm.cs:line 48
   at System.Windows.Forms.Form.OnShown(EventArgs e)
   at System.Windows.Forms.Form.CallShownEvent()
   at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   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()

Any ideas? Has this changed some how from Q3 -> SP1?

35 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 17 Dec 2010, 11:01 PM
Hello,

I haven't been able to replicate your issue. Are you able to provide a small, simple exmaple of a grid view where I can replicate this to look into it for you?
thanks
Richard
0
Marc-Andre
Top achievements
Rank 1
answered on 18 Dec 2010, 11:59 PM
Same here.. my form won't load because of that too... for me it happens when I run Best fit Columns from the designer..  when my form tries to load and I get an error message saying the index was out of range, the same error I get when I run the Best fit columns from the designer..

However, it happens only for one particular gridview. I deleted it, recreated it, attached the datasource, it worked fine until I clicked the best fit columns and here we go again, the grid is screwed..


thanks
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 12:16 AM
it seems to happen when AutoSizeColumnsMode is set to Fill..
0
Richard Slade
Top achievements
Rank 2
answered on 19 Dec 2010, 12:38 PM
Hi
I still haven't been able to replicate this at the moment, but it sounds quite sporadic. I added a RadGridView, added some columns through the property builder, set the AutoSizeColumnMode to fill and then on the Smart Tag, hit BestFitColumns.

regards,
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Dec 2010, 05:17 PM
Hello guys,

I've noticed this problem also, but only when inside a BeginUpdate() / EndUpdate(), if you are calling this from within, please try addin the BestFitColumns() after the EndUpdate().

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 05:18 PM
Mine had a datasource with manually added columns.. when I changed the header text, hide some columns, etc. it happened..

but like you said, it is very sporadic. I only have one problematic grid out of 200... but something is causing that for sure and deleting and recreating the grid does not help..

thanks for trying
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 05:20 PM
To fix the issue during runtime, I had to set the autosizecolumnmode=true after calling the bestfitcolumns... calling it before caused the index out of range issue
0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Dec 2010, 05:25 PM
Hello again,

And you are calling the BestFitColumns in the DataBindingComplete event? And can you please tell me if you are using BeginUpdate() / EndUpdate() or DeferRefresh()?

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 06:16 PM
Hi, no i'm calling the bestfitcolumn in the form's load event, after filling the datasource:

    Private Sub co_pnl_Payables_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            RadGridLocalizationProvider.CurrentProvider = New Controls.FrenchRadControls.RadGridView
            ChargerPayables()  'I load the dataset here

            SetInitialFilters(dgPayable)
            dgPayable.BestFitColumns()
            dgPayable.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill

            LoadLayout(Me.Name + "." + dgPayable.Name, dgPayable, CalculMenuStrip)
        Catch ex As Exception

        End Try
    End Sub

Like I said, the problem also occur when you click BestFitColumn in the designer.. only when AutoSizeColumnMode=Fill

Thanks guys

0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Dec 2010, 06:18 PM
Hello again,

Please don't do that, please register for the DataBindingComplete event before setting the datasource, and fire the BestFitColumns() in the DataBindingComplete event and let me know if this solved your problem

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 06:20 PM
I could, but I didn't experience that before SP1.. also what must I do in the designer?


I will try and let you know
0
Marc-Andre
Top achievements
Rank 1
answered on 19 Dec 2010, 06:30 PM
Okay here are the results of my test.

If I set the autosizecolumnmode to None, then there's no problem with the BestFitColumn in the DataBindingComplete. However, if I set the autosizecolumnmode to Fill, I cannot even load the form, I get the error message when I fire the form.show event.

More details to come if needed, I got to go.

thanks
0
Bradley Schultz
Top achievements
Rank 1
answered on 19 Dec 2010, 10:50 PM
I get the same result. Further information, even though there is no error is AutoSize is set to None, it does not do the best fit either...
0
Marc-Andre
Top achievements
Rank 1
answered on 20 Dec 2010, 03:24 AM
Bradley, can you try something, I also found that I cannot group by a column, only for the problematic grid. I cannot also hide/show columns...

Worst, I copied and pasted the grid on top of the problematic one (so it should react the same way...) and I was able to group by column, but still can't hide/show. Another weird behaviour, when I right-click on the newly created grid using my custom contextmenu, it shows it no problem but once I clicked on an item, it shows another contextmenu that is not even in the form... wow.

I don't know what else to check..
0
Richard Slade
Top achievements
Rank 2
answered on 20 Dec 2010, 08:06 AM
Hello Marc-Andre,

The reason I suspect you are getting the more than one action after clicking on your context menu is that you are manually adding event handlers in the ContextMenuOpening event for your click event. Each time you open the context menu you are creating the event handler on top of the one that already exists and therefore the click event is firing +1 times each time you open the context menu.
Either remove the handler before adding it, or move this code out of the ContextMenuOpening event
Regards,
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Dec 2010, 08:52 AM
Hello guys,

Ok, can someone please post a full example so we can find a solution to this problem? Like i said the only problems I've been experiencing is that with the BestFitColumns() inside BeginUpdate / EndUpdate.

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Bradley Schultz
Top achievements
Rank 1
answered on 20 Dec 2010, 06:24 PM
Did some more troubleshooting and it seems like this is occurring when both the MinWidth and the MaxWidth for a column are set to the same values.

On a side note, above mentions running BestFitColumns on DataBindingComplete. Is this just a best practice or a requirement(not in docuemtation). Also talks about calling on the MasterTemplate vs on the grid. Please clarify when BestFitColumns can be used.

b  r  a  d
0
Marc-Andre
Top achievements
Rank 1
answered on 20 Dec 2010, 06:29 PM
Brad, thanks for pointing this one out, I also have a column with the same minWidth and maxWidth..

I will do some tests on my end and let you know
0
Marc-Andre
Top achievements
Rank 1
answered on 20 Dec 2010, 06:41 PM
Changed the minWidth and I still have the same issue...

Emmanuel, personnaly I cannot provide a full exemple my project is way too big and complex.. I will try to find something else..
0
Marc-Andre
Top achievements
Rank 1
answered on 20 Dec 2010, 06:59 PM
Whatever test I try, the grid must have the property AutoSizeColumnMode=None in order to use BestFitColumns...

I can then call the AutoSizeColumnMode and set it to Fill, but most of the times I get various undesired behaviour.. (grid not being refreshed after grouping, filter row not working, BestFitColumns either give an error message index out of bound or the column width are badly calculted, etc.)

That being said, since it seems to happend on all my grids now, I will try to create a small project and send it to you all later today...

thanks
0
Richard Slade
Top achievements
Rank 2
answered on 21 Dec 2010, 03:23 PM
Hi,

Just to contribute, this is the first time I've also experienced now an issue with BestFit. Here is my stack trace.

Object reference not set to an instance of an object.
  
   at Telerik.WinControls.UI.StretchColumnLayoutHelper.StartColumnResize(GridViewColumn column)
   at Telerik.WinControls.UI.TableViewRowLayout.StartColumnResize(GridViewColumn column)
   at Telerik.WinControls.UI.TableViewRowLayout.StretchColumn(GridViewColumn column, Int32 desiredWidth)
   at Telerik.WinControls.UI.BestFitHelper.SetColumnWidth(GridViewColumn column, Single desiredWidth)
   at Telerik.WinControls.UI.BestFitHelper.BestFitColumnsCore()
   at Telerik.WinControls.UI.BestFitHelper.ProcessRequests()
   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.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.ComponentLayoutElementTree.PerformInnerLayout(Boolean performMeasure, Int32 x, Int32 y, Int32 width, Int32 height)
   at Telerik.WinControls.RadControl.GetInitialDesiredSize(Size availableSize, Boolean useNewLayoutSystem)
   at Telerik.WinControls.RadControl.OnLoad(Size desiredSize)
   at Telerik.WinControls.RadControl.LoadElementTree(Size desiredSize)
   at Telerik.WinControls.RadControl.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at Telerik.WinControls.UI.RadPageViewPage.set_Visible(Boolean value)
   at Telerik.WinControls.UI.RadPageViewElement.SetSelectedContent(RadPageViewItem item)
   at Telerik.WinControls.UI.RadPageViewElement.SetSelectedItem(RadPageViewItem item)
   at Telerik.WinControls.UI.RadPageViewElement.OnSelectedPageChanged(RadPageViewEventArgs e)
   at Telerik.WinControls.UI.RadPageView.SetSelectedPage(RadPageViewEventArgs e)
   at Telerik.WinControls.UI.RadPageView.set_SelectedPage(RadPageViewPage value)
   at Telerik.WinControls.UI.RadPageViewElement.SelectItem(RadPageViewItem item)
   at Telerik.WinControls.UI.RadPageViewElement.OnItemMouseDown(RadPageViewItem sender, MouseEventArgs e)
   at Telerik.WinControls.UI.RadPageViewStripElement.OnItemMouseDown(RadPageViewItem sender, MouseEventArgs e)
   at Telerik.WinControls.UI.RadPageViewItem.OnMouseDown(MouseEventArgs e)
   at Telerik.WinControls.RadElement.OnCLREventsRise(RoutedEventArgs args)
   at Telerik.WinControls.RadElement.OnBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.OnBubbleEvent(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.DoMouseDown(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseDown(MouseEventArgs e)
   at Telerik.WinControls.RadControl.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 Telerik.WinControls.RadNCEnabledControl.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 as you've said, this only happens in Fill mode. I'll also look into this as we've never had this issue before.
Richard
0
Marc-Andre
Top achievements
Rank 1
answered on 21 Dec 2010, 03:33 PM
Great, I'm glad you found it! :)
0
Richard Slade
Top achievements
Rank 2
answered on 21 Dec 2010, 05:05 PM
Hi All,

Ok, in a new project I can replicate this every time now. The problem is a mixture of two things.
In order to replicate this you need to have
  • AutoSizeColumnsMode set to Fill AND
  • Have at least one GroupDescriptor

See the following code: Either change the code to remove the GroupDescriptor or, change to None for AutoSizeColumnsMode and BestFit works fine.
(this is a RadGridView and a RadButton on a RadForm)

Imports Telerik.WinControls.UI
Imports System.ComponentModel
Imports Telerik.WinControls.Data
  
Public Class Form1
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
        Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
        Me.RadGridView1.EnableGrouping = True
        Me.RadGridView1.ShowGroupPanel = False
  
        Dim people As New BindingList(Of Person)
        people.Add(New Person("Richard", 40, False))
        people.Add(New Person("Peter", 104, True))
        people.Add(New Person("Chris", 43, False))
        people.Add(New Person("Oliver", 12, False))
  
        Try
            Me.Cursor = Cursors.WaitCursor
            Me.RadGridView1.BeginUpdate()
            Me.RadGridView1.DataSource = Nothing
            Me.RadGridView1.DataSource = people
  
  
            Me.RadGridView1.GroupDescriptors.Clear()
            Dim descriptor As New GroupDescriptor()
            descriptor.GroupNames.Add("HasBeard", ListSortDirection.Ascending)
            Me.RadGridView1.GroupDescriptors.Add(descriptor)
  
            Me.RadGridView1.EndUpdate()
        Finally
            Me.Cursor = Cursors.Default
        End Try
  
    End Sub
  
    Private Sub RadButtonBestFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButtonBestFit.Click
        Me.RadGridView1.BestFitColumns()
    End Sub
End Class
  
Public Class Person
  
    Public Sub New(ByVal name As String, ByVal age As Integer, ByVal hasBeard As Boolean)
        Me.Name = name
        Me.Age = age
        Me.HasBeard = hasBeard
    End Sub
  
    Public Property Name As String
    Public Property Age As Integer
    Public Property HasBeard As Boolean
  
End Class

Richard
0
Svett
Telerik team
answered on 22 Dec 2010, 05:08 PM
Hello Guys,

@Richard: Thank you for your help in the forums.

@Marc-Andre: I did not manage to reproduce the issue with Richard's code snippet. I tried to experience it with Q3 2010 (2010.3 10.1109) and Q3 2010 SP1 (2010.3 10.1215). I would kindly ask you to open a support ticket with an attached project where the issue can be reproduced. This will allow us to investigate the case further.

Greetings,
Svett
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Richard Slade
Top achievements
Rank 2
answered on 22 Dec 2010, 05:18 PM
Hi Svett,

I can send this on now as I have the project ready. I'll open a support ticket and include a video too.
Hope this helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 22 Dec 2010, 05:27 PM
Ticket opened with Id 378694
and video with the ticket is here
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 23 Dec 2010, 04:09 PM
Hi Guys,

Just to let you know I've had a note that this is an issue that will be fixed in one of the upcoming releases. I understand that a workaround will be posted shortly.
Regards,
Richard
0
Svett
Telerik team
answered on 27 Dec 2010, 04:30 PM
Hello Guys,

@Richard: Thank you for opening the support ticket.

@Bradley Schultz: You can use the following code snippet to work around this issue. The issue will be addressed in our next major release.

VB Version:

Public Class MyTableViewRowLayout
    Inherits TableViewRowLayout
    Public Overrides Sub StartColumnResize(ByVal column As GridViewColumn)
        If column.IsGrouped AndAlso (Not column.OwnerTemplate.ShowGroupedColumns) Then
            Return
        End If
 
        MyBase.StartColumnResize(column)
    End Sub
End Class
 
Public Class MyTableViewDefinition
    Inherits TableViewDefinition
    Public Overrides Function CreateRowLayout() As IGridRowLayout
        Return New MyTableViewRowLayout()
    End Function
 
End Class

Me.RadGridView1.ViewDefinition = New MyTableViewDefinition()
Dim rowLayout As New MyTableViewRowLayout()
rowLayout.Initialize(Me.RadGridView1.TableElement)
Me.RadGridView1.TableElement.ViewElement.RowLayout = rowLayout

C# Version:

public class MyTableViewRowLayout : TableViewRowLayout
{
    public override void StartColumnResize(GridViewColumn column)
    {
        if (column.IsGrouped && !column.OwnerTemplate.ShowGroupedColumns)
        {
            return;
        }
 
        base.StartColumnResize(column);
    }
}
 
public class MyTableViewDefinition : TableViewDefinition
{
    public override IRowView CreateViewUIElement(GridViewInfo viewInfo)
    {
        return base.CreateViewUIElement(viewInfo);
    }
    public override System.Type RowLayoutType
    {
        get
        {
            return typeof(MyTableViewRowLayout);
        }
    }
    public override IGridRowLayout CreateRowLayout()
    {
        return new MyTableViewRowLayout();
    }
}

this.radGridView1.ViewDefinition = new MyTableViewDefinition();
MyTableViewRowLayout rowLayout = new MyTableViewRowLayout();
rowLayout.Initialize(this.radGridView1.TableElement);
this.radGridView1.TableElement.ViewElement.RowLayout = rowLayout;

I hope this helps.

Regards,
Svett
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Richard Slade
Top achievements
Rank 2
answered on 04 Jan 2011, 11:33 PM
Hi All,

Just an extra note so you can track this issue in PITS. the link is here
All the best
Richard
0
Joel Kraft
Top achievements
Rank 2
answered on 28 Feb 2011, 05:41 PM
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).

0
Svett
Telerik team
answered on 02 Mar 2011, 02:21 PM
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!
0
John
Top achievements
Rank 1
answered on 27 Jan 2015, 05:35 PM
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: 







0
Hristo
Telerik team
answered on 30 Jan 2015, 09:14 AM
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.

 
0
Zohreh
Top achievements
Rank 1
answered on 05 Oct 2016, 05:15 AM

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

0
Hristo
Telerik team
answered on 05 Oct 2016, 02:09 PM
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.
Tags
GridView
Asked by
Bradley Schultz
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Marc-Andre
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Bradley Schultz
Top achievements
Rank 1
Svett
Telerik team
Joel Kraft
Top achievements
Rank 2
John
Top achievements
Rank 1
Hristo
Telerik team
Zohreh
Top achievements
Rank 1
Share this question
or