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

Q3 and CastException

3 Answers 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ludovic Gerbault
Top achievements
Rank 1
Ludovic Gerbault asked on 04 Nov 2009, 04:13 PM
Hello

Today, I've updated my application with the latest Q3 release (2009.3.1103.1030), I updated my old code as well.

I have a grid that I'm building completely in code behind, by manually adding the gridcolumns (datacolumns, imagecolumns...).
The datatype of each column is set according to the datasource.

Once it's done, I'm setting the itemsource

The weird thing is that, depending on the datasource, it sometimes works.
Second weird thing, when I debug the application on the faulty datasource, no errors shows up, the program runs fine, and everything is correctly displayed.

Here's the error message :

Erreur : Unhandled Error in Silverlight Application
Code: 4004    
Category: ManagedRuntimeError       
Message: System.InvalidCastException: Le cast spécifié n'est pas valide.
   à Telerik.Windows.Controls.GridViewDataColumn.CreateCellElement(GridViewCell cell, Object dataItem)
   à Telerik.Windows.Controls.GridView.GridViewCell.CreateCellElement(GridViewColumn column, Object dataItem)
   à Telerik.Windows.Controls.GridView.GridViewCell.BuildVisualTree()
   à Telerik.Windows.Controls.GridView.GridViewCell.SetCellElement()
   à Telerik.Windows.Controls.GridView.GridViewRow.PrepareCell(GridViewCellBase cellBase, GridViewColumn column)
   à Telerik.Windows.Controls.GridView.DataCellsPresenter.PrepareContainerForItemOverride(DependencyObject element, Object item)
   à System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
   à System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.InsertNewContainer(Int32 childIndex, UIElement container)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.GenerateChild(IItemContainerGenerator generator, Size constraint, GridViewColumn column, Int32& childIndex, Size& childSize)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.GenerateChild(IItemContainerGenerator generator, Size constraint, GridViewColumn column, IDisposable& generatorState, Int32& childIndex, Size& childSize)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.DetermineRealizedColumnsBlockList(Size constraint)
   à Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureOverride(Size constraint)
   à System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Any idea why this is happening ?



3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 04 Nov 2009, 04:25 PM
Hello,

Can you send us an example (via support ticket) where we can debug this?

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 04 Nov 2009, 05:30 PM
Well, it's gonna be kinda hard to reproduce the exact dataset and code to reproduce this bug, buty I can give you a huge hint.

I narrowed down this cast problem to the datacolumns that has the boolean datatype.

Here's the definition :

 case "5": GridViewDataColumn col5 = new GridViewDataColumn() { Header = row["Name"].ToString(), DataType = typeof(Boolean), DataMemberBinding = new Binding() { Path = new PropertyPath(path) }, CellStyle = this.Resources["gridviewCellStyle"as Style, UniqueName = path }; 
           ClientsGrid.Columns.Add(col5); 
           break

In the dataset, there is either the string "true" or the string "false".

In the previous versions, usually, it would display automatically a checkbox checked or not depending on the value. Now, it raises a cast exception.
0
Vlad
Telerik team
answered on 05 Nov 2009, 07:19 AM
Hi

We believe that we found a case which can cause such problem and this was fixed immediately!. Please open a formal support ticket and we will send you our latest binaries.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Ludovic Gerbault
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ludovic Gerbault
Top achievements
Rank 1
Share this question
or