InvalidCastException

3 posts, 1 answers
  1. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 25 Aug 2011 Link to this post

    I have a grid that I have set the IsReadOnly to true.  When I am in the grid on any cell, if I press the Enter key, I get the following error.

    Unable to cast object of type 'System.Windows.Input.KeyEventArgs' to type 'FullyLoadedCostLibrary.BareDriveCosts'.


    StackTrace:
       at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Core\Data\Extensions\FuncExtensions.cs:line 24
       at Telerik.Windows.Data.FunctionComparer.Compare(Object x, Object y) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Core\Data\FunctionComparer.cs:line 34
       at System.Collections.Generic.ArraySortHelper`1.InternalBinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
       at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)

    I'm using version 2011.2.712.40 WPF

    My grid is defined
            <telerik1:RadGridView Name="bareDriveCostsListRadGridView"
                   DataContext="{StaticResource bareDriveCostsListViewModelModelViewSource}" 
    			   ItemsSource="{Binding ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True}" AutoGenerateColumns="False" CanUserDeleteRows="False"
                   AutoExpandGroups="True" DataLoaded="bareDriveCostsListRadGridView_DataLoaded" SelectionUnit="Cell"
                   IsReadOnly="{Binding Source={StaticResource bareDriveCostsListViewModelViewSource}, Path=CanEdit, Converter={StaticResource NotConverter}}">


    I have some columns defined like this
    <telerik1:GridViewMaskedTextBoxColumn Name="HistoryColumn4" DataFormatString="{}{0:n}"  MaskType="Numeric" Mask="n"  Header="{Binding Path=HistoryName4}" Background="LightGray" DataMemberBinding="{Binding Path=History4.Cost}" IsReadOnly="True" TextAlignment="Right"  IsFilterable="False" IsSortable="False" />
    
    and some like this
                    <telerik1:GridViewMaskedTextBoxColumn Name="BareDriveCostColumn" Header="Bare Drive Cost" DataMemberBinding="{Binding Path=Cost}" DataFormatString="{}{0:n}" TextAlignment="Right" MaskType="Numeric" Mask="n"  IsFilterable="False" IsSortable="False" >
                        <telerik1:GridViewMaskedTextBoxColumn.CellTemplate>
                            <DataTemplate>
                                <Grid MouseRightButtonDown="Cell_MouseRightButtonDown" DataContext="{Binding}"
                                      ToolTip="{DynamicResource toolTipTemplate}">
                                    <TextBlock Text="{Binding Cost}"/>
                                    <Border VerticalAlignment="Top" Width="5" Height="5" HorizontalAlignment="Right" Background="Red" Visibility="{Binding Comments,Converter={StaticResource MyConverter}}"/>
                                </Grid>
                            </DataTemplate>
                        </telerik1:GridViewMaskedTextBoxColumn.CellTemplate>                                    
                    </telerik1:GridViewMaskedTextBoxColumn>
    it errors on any of them.


  2. Answer
    Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 26 Aug 2011 Link to this post

    Hello David Brenchley,

    Thank you for the feedback.
    The exception has already been fixed and the fix for it is part of the latest internal build. 
     
    Kind regards,
    Yordanka
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 26 Aug 2011 Link to this post

    Awesome.  Thank you.
Back to Top