Binding Error for RadComboBox in DataForm

6 posts, 0 answers
  1. Matt Duffield
    Matt Duffield avatar
    7 posts
    Member since:
    Jul 2009

    Posted 28 Aug 2009 Link to this post

    I have a DataForm that is bound to a collection.  When the DataForm is displayed with a RadComboBox, I always get the following error even the it is showing the correct value:
    Can't convert type null to type System.Int32.

    Looking at my output window I see that it is throwing a System.Windows.Data.Error: ConvertBack cannot convert value 'null' (type 'null'). BindingExpression: Path='mm_df_DataTableId' DataItem='mm_df_DataField : 357' (HashCode=51192804); target element is 'Telerik.Windows.Controls.RadComboBox' (Name=''); target property is 'SelectedValue' (type 'System.Object').. System.InvalidOperationException: Can't convert type null to type System.Int32.
       at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
       at System.Windows.Data.BindingExpression.UpdateValue().

    Here is my XAML snippet:
    <input:RadComboBox
    DisplayMemberPath="mm_dt_FriendlyName"
    SelectedValuePath="mm_dt_DataTableIdent"
    SelectedValue="{Binding Path=mm_df_DataTableId, Mode=TwoWay}"
            HorizontalAlignment="Left"
            Width="200">
    <i:Interaction.Behaviors>
             <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" />
    </i:Interaction.Behaviors>
    </input:RadComboBox>

    Please advise,

    Matt
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 31 Aug 2009 Link to this post

    Hello Matt,

    I guess that the poperty mm_df_DataTableId is not nullable, hence the problem. If there is no selected item in RadComboBox, the SelectedItem/SelectedValue properties are null.

    If this does not help, please, send us a simple application that can be used to reproduce the problem and we will respond with a solution ASAP.

    Best wishes,
    Valeri Hristov
    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.
  3. DevCraft banner
  4. Matt Duffield
    Matt Duffield avatar
    7 posts
    Member since:
    Jul 2009

    Posted 31 Aug 2009 Link to this post

    Hi Valeri,

    It is coming up with the correctly selected item but the DataForm is showing an error with an ErrorSummary.  Since the underlying record actually does have a valid entry, I would have not expected this to happen.  What must I do to get this to work properly?

    P.S. - mm_df_DataTableId is marked as non-nullable.

    Regards,

    Matt
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 01 Sep 2009 Link to this post

    Hi Matt,

    Could you please, prepare a simple application that can be used to reproduce the problem? If I prepare a sample, it will be a shot in the dark, since I don't know how do you put RadComboBox in the DataForm (EditableTemplate, AutogeneratingField event, etc.). You can attach an application to a new support ticket, the forums attachments are disabled.

    Sincerely yours,
    Valeri Hristov
    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.
  6. Matt Duffield
    Matt Duffield avatar
    7 posts
    Member since:
    Jul 2009

    Posted 01 Sep 2009 Link to this post

    Valeri,

    I can post the XAML of the View that is giving this problem.  This application uses Prism V2, Ria Services, etc. and wouldn't be feasible to send to you as a whole.  I believe that the XAML should give you a good indication as to what is going on.  Basically the screen has three regions, a Table selector region which is a DataGrid; a Field selector region which is a DataGrid; a DataForm that allow editing of the Fields.  The DataGrid for the Table's SelectionChanged event is what filters the data for the Fields DataGrid and the DataForm.

    See the following XAML:
    1 <inf:ViewBase 
    2     x:Class="CodeMaster.MetaModel.Silverlight.DataFieldView" 
    3     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    4     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    5     xmlns:inf="clr-namespace:Core.Infrastructure.Silverlight.UI.View;assembly=Core.Infrastructure.Silverlight" 
    6     xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls" 
    7     xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"    
    8     xmlns:dc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
    9     xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    10     xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    11     xmlns:commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation" 
    12     xmlns:trg="clr-namespace:Core.Infrastructure.Silverlight.Triggers;assembly=Core.Infrastructure.Silverlight" 
    13     xmlns:beh="clr-namespace:Core.Infrastructure.Silverlight.Behaviors;assembly=Core.Infrastructure.Silverlight" 
    14     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    15     xmlns:lc="clr-namespace:Core.Infrastructure.Silverlight.UI.Controls;assembly=Core.Infrastructure.Silverlight" 
    16     xmlns:domain="clr-namespace:CodeMaster.Data.Web;assembly=CodeMaster.Data.Silverlight" 
    17     xmlns:input="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
    18     > 
    19     <inf:ViewBase.DataContext> 
    20         <Binding Path="DataFieldViewModel" Source="{StaticResource MetaModelModule}" /> 
    21     </inf:ViewBase.DataContext> 
    22     <Grid x:Name="LayoutRoot" Background="White"
    23         <Grid.ColumnDefinitions> 
    24             <ColumnDefinition Width="Auto" /> 
    25             <ColumnDefinition Width="Auto" /> 
    26             <ColumnDefinition Width="*" /> 
    27         </Grid.ColumnDefinitions> 
    28         <riaControls:DomainDataSource  
    29             x:Name="ddsDataTables" 
    30             QueryName="GetMm_dt_DataTables" 
    31             AutoLoad="True" 
    32             LoadSize="20" 
    33             > 
    34             <riaControls:DomainDataSource.DomainContext> 
    35                 <domain:MetaModelDomainContext /> 
    36             </riaControls:DomainDataSource.DomainContext> 
    37             <riaControls:DomainDataSource.SortDescriptors> 
    38                 <riaData:SortDescriptor PropertyPath="mm_dt_FriendlyName" Direction="Ascending" /> 
    39             </riaControls:DomainDataSource.SortDescriptors> 
    40         </riaControls:DomainDataSource> 
    41         <riaControls:DomainDataSource  
    42             x:Name="dds" 
    43             DomainContext="{Binding DomainContext}" 
    44             QueryName="GetMm_df_DataFields" 
    45             AutoLoad="True" 
    46             > 
    47             <riaControls:DomainDataSource.SortDescriptors> 
    48                 <riaData:SortDescriptor PropertyPath="mm_dt_DataTable.mm_dt_FriendlyName" Direction="Ascending" /> 
    49                 <riaData:SortDescriptor PropertyPath="mm_df_FieldOrder" Direction="Ascending" /> 
    50             </riaControls:DomainDataSource.SortDescriptors> 
    51             <riaControls:DomainDataSource.FilterDescriptors> 
    52                 <riaData:FilterDescriptorCollection> 
    53                     <riaData:FilterDescriptor PropertyPath="mm_df_DataTableId" 
    54                                               Operator="IsEqualTo"
    55                         <riaData:ControlParameter PropertyName="SelectedItem.mm_dt_DataTableIdent" 
    56                                                   RefreshEventName="SelectionChanged" 
    57                                                   ControlName="dgTableFilter" /> 
    58                     </riaData:FilterDescriptor> 
    59                 </riaData:FilterDescriptorCollection> 
    60             </riaControls:DomainDataSource.FilterDescriptors> 
    61         </riaControls:DomainDataSource> 
    62         <riaControls:DomainDataSource  
    63             x:Name="ddsDataFormatTypes" 
    64             DomainContext="{Binding DomainContext}" 
    65             QueryName="GetMm_xdft_DataFormatTypes" 
    66             AutoLoad="True" 
    67             > 
    68             <riaControls:DomainDataSource.SortDescriptors> 
    69                 <riaData:SortDescriptor PropertyPath="mm_xdft_Name" Direction="Ascending" /> 
    70             </riaControls:DomainDataSource.SortDescriptors> 
    71         </riaControls:DomainDataSource> 
    72         <riaControls:DomainDataSource  
    73             x:Name="ddsObjectDataTypes" 
    74             DomainContext="{Binding DomainContext}" 
    75             QueryName="GetMm_xodt_ObjectDataTypes" 
    76             AutoLoad="True" 
    77             > 
    78             <riaControls:DomainDataSource.SortDescriptors> 
    79                 <riaData:SortDescriptor PropertyPath="mm_xodt_Name" Direction="Ascending" /> 
    80             </riaControls:DomainDataSource.SortDescriptors> 
    81         </riaControls:DomainDataSource> 
    82         <riaControls:DomainDataSource  
    83             x:Name="ddsSqlDataTypes" 
    84             DomainContext="{Binding DomainContext}" 
    85             QueryName="GetMm_xsdt_SqlDataTypes" 
    86             AutoLoad="True" 
    87             > 
    88             <riaControls:DomainDataSource.SortDescriptors> 
    89                 <riaData:SortDescriptor PropertyPath="mm_xsdt_Name" Direction="Ascending" /> 
    90             </riaControls:DomainDataSource.SortDescriptors> 
    91         </riaControls:DomainDataSource> 
    92  
    93  
    94         <lc:HeaderedContentControl 
    95             x:Name="hccDataTableCollection" 
    96             Grid.Column="0" 
    97             FooterVisible="True" 
    98             Margin="5" 
    99             ItemsSource="{Binding ElementName=ddsDataTables, Path=Data}" 
    100             > 
    101             <lc:HeaderedContentControl.HeaderTemplate> 
    102                 <DataTemplate> 
    103                     <Grid Background="{StaticResource Header_BackgroundGradient}"
    104                         <Grid.ColumnDefinitions> 
    105                             <ColumnDefinition Width="Auto" /> 
    106                             <ColumnDefinition Width="Auto" /> 
    107                         </Grid.ColumnDefinitions> 
    108                         <TextBlock Text="Tables" Style="{StaticResource TextBlockH1Style}"/> 
    109                     </Grid> 
    110                 </DataTemplate> 
    111             </lc:HeaderedContentControl.HeaderTemplate> 
    112  
    113             <data:DataGrid 
    114                     x:Name="dgTableFilter" 
    115                     ItemsSource="{Binding ElementName=ddsDataTables, Path=Data}" 
    116                     SelectionMode="Single" 
    117                     AutoGenerateColumns="False" 
    118                     IsReadOnly="True" 
    119                     > 
    120                 <data:DataGrid.Columns> 
    121                     <data:DataGridTextColumn Header="Table Name" Binding="{Binding mm_dt_FriendlyName}" /> 
    122                 </data:DataGrid.Columns> 
    123             </data:DataGrid> 
    124  
    125             <lc:HeaderedContentControl.FooterTemplate> 
    126                 <DataTemplate> 
    127                     <Grid Margin="7,1,0,1"
    128                         <Grid.ColumnDefinitions> 
    129                             <ColumnDefinition Width="Auto" /> 
    130                             <ColumnDefinition Width="Auto"/> 
    131                         </Grid.ColumnDefinitions> 
    132                         <TextBlock Text="Count:" VerticalAlignment="Center" /> 
    133                         <TextBox Grid.Column="1" Text="{Binding ElementName=hccDataTableCollection, Path=Count}" IsReadOnly="True" VerticalAlignment="Center" Style="{StaticResource TextBoxStyle}" Width="50" Margin="2,0,0,5"  /> 
    134                     </Grid> 
    135                 </DataTemplate> 
    136             </lc:HeaderedContentControl.FooterTemplate> 
    137         </lc:HeaderedContentControl> 
    138  
    139         <lc:HeaderedContentControl 
    140             x:Name="hccDataFieldCollection" 
    141             Grid.Column="1" 
    142             Margin="5" 
    143             ItemsSource="{Binding ElementName=dds, Path=Data}" 
    144             > 
    145             <lc:HeaderedContentControl.HeaderTemplate> 
    146                 <DataTemplate> 
    147                     <Grid Background="{StaticResource Header_BackgroundGradient}"
    148                         <TextBlock Text="Data Fields" Style="{StaticResource TextBlockH1Style}"/> 
    149                     </Grid> 
    150                 </DataTemplate> 
    151             </lc:HeaderedContentControl.HeaderTemplate> 
    152  
    153             <data:DataGrid 
    154                         x:Name="dgDataFields" 
    155                         ItemsSource="{Binding ElementName=dds, Path=Data}" 
    156                         SelectedItem="{Binding CurrentItem, Mode=TwoWay}" 
    157                         SelectionMode="Single" 
    158                         AutoGenerateColumns="False" 
    159                         IsReadOnly="True" 
    160                         > 
    161                 <data:DataGrid.Columns> 
    162                     <data:DataGridTextColumn Header="Field Name" Binding="{Binding mm_df_FriendlyName}" /> 
    163                 </data:DataGrid.Columns> 
    164             </data:DataGrid> 
    165  
    166             <lc:HeaderedContentControl.FooterTemplate> 
    167                 <DataTemplate> 
    168                     <Grid Margin="7,1,0,1"
    169                         <Grid.ColumnDefinitions> 
    170                             <ColumnDefinition Width="Auto" /> 
    171                             <ColumnDefinition Width="Auto"/> 
    172                         </Grid.ColumnDefinitions> 
    173                         <TextBlock Text="Count:" VerticalAlignment="Center" /> 
    174                         <TextBox Grid.Column="1" Text="{Binding ElementName=hccDataFieldCollection, Path=Count}" IsReadOnly="True" VerticalAlignment="Center" Style="{StaticResource TextBoxStyle}" Width="50" Margin="2,0,0,5"  /> 
    175                     </Grid> 
    176                 </DataTemplate> 
    177             </lc:HeaderedContentControl.FooterTemplate> 
    178         </lc:HeaderedContentControl> 
    179  
    180  
    181         <lc:DataForm 
    182                 x:Name="dfDetail" 
    183                 Grid.Column="2" 
    184                 AutoGenerateFields="False" 
    185                 ItemsSource="{Binding ElementName=dds, Path=Data}" 
    186                 Header="Data Fields" 
    187                 Margin="10,5,5,5" 
    188                 AutoCommit="False" 
    189                 AutoEdit="False" 
    190                 > 
    191             <i:Interaction.Triggers> 
    192                 <i:EventTrigger EventName="EditEnded"
    193                     <trg:ExecuteCommandTrigger TargetCommand="ActionCommand" UserState="EditEnded" /> 
    194                 </i:EventTrigger> 
    195                 <i:EventTrigger EventName="DeletingItem"
    196                     <trg:ExecuteCommandTrigger TargetCommand="ActionCommand" UserState="DeletingItem" /> 
    197                 </i:EventTrigger> 
    198             </i:Interaction.Triggers> 
    199  
    200  
    201             <dc:DataForm.ReadOnlyTemplate> 
    202                 <DataTemplate> 
    203                     <StackPanel Orientation="Horizontal"
    204                         <StackPanel dc:DataField.IsFieldGroup="True"
    205                             <dc:DataField Label="Data Table"
    206                                 <input:RadComboBox 
    207                                     DisplayMemberPath="mm_dt_FriendlyName" 
    208                                     SelectedValuePath="mm_dt_DataTableIdent" 
    209                                     SelectedValue="{Binding Path=mm_df_DataTableId, Mode=TwoWay}" 
    210                                     HorizontalAlignment="Left" 
    211                                     Width="200" 
    212                                     IsEnabled="False" 
    213                                     > 
    214                                     <i:Interaction.Behaviors> 
    215                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
    216                                     </i:Interaction.Behaviors> 
    217                                 </input:RadComboBox> 
    218                             </dc:DataField> 
    219                             <dc:DataField Label="Field Identity" IsReadOnly="True"
    220                                 <TextBox Text="{Binding mm_df_DataFieldIdent, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    221                             </dc:DataField> 
    222                             <dc:DataField Label="Field Name"
    223                                 <TextBox Text="{Binding mm_df_FieldName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
    224                             </dc:DataField> 
    225                             <dc:DataField Label="Friendly Name"
    226                                 <TextBox Text="{Binding mm_df_FriendlyName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
    227                             </dc:DataField> 
    228                             <dc:DataField Label="Default Value"
    229                                 <TextBox Text="{Binding mm_df_DefaultValue, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
    230                             </dc:DataField> 
    231                             <dc:DataField Label="Is Primary"
    232                                 <CheckBox IsChecked="{Binding mm_df_IsPrimary, Mode=TwoWay}" IsEnabled="False" /> 
    233                             </dc:DataField> 
    234                             <dc:DataField Label="Is Identity"
    235                                 <CheckBox IsChecked="{Binding mm_df_IsIdentity, Mode=TwoWay}" IsEnabled="False" /> 
    236                             </dc:DataField> 
    237                             <dc:DataField Label="Allow Nulls"
    238                                 <CheckBox IsChecked="{Binding mm_df_AllowNulls, Mode=TwoWay}" IsEnabled="False" /> 
    239                             </dc:DataField> 
    240                             <dc:DataField Label="SQL Data Type"
    241                                 <input:RadComboBox 
    242                                     DisplayMemberPath="mm_xsdt_Name" 
    243                                     SelectedValuePath="mm_xsdt_SqlDataTypeIdent" 
    244                                     SelectedValue="{Binding Path=mm_df_SqlDataTypeId, Mode=TwoWay}" 
    245                                     HorizontalAlignment="Left" 
    246                                     Width="200" 
    247                                     IsEnabled="False" 
    248                                     > 
    249                                     <i:Interaction.Behaviors> 
    250                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsSqlDataTypes" /> 
    251                                     </i:Interaction.Behaviors> 
    252                                 </input:RadComboBox> 
    253                             </dc:DataField> 
    254                             <dc:DataField Label="Length"
    255                                 <TextBox Text="{Binding mm_df_Length, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    256                             </dc:DataField> 
    257                             <dc:DataField Label="Precision"
    258                                 <TextBox Text="{Binding mm_df_Precision, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    259                             </dc:DataField> 
    260                             <dc:DataField Label="Scale"
    261                                 <TextBox Text="{Binding mm_df_Scale, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    262                             </dc:DataField> 
    263                             <dc:DataField Label="Object Data Type"
    264                                 <input:RadComboBox 
    265                                     DisplayMemberPath="mm_xodt_Name" 
    266                                     SelectedValuePath="mm_xodt_ObjectDataTypeIdent" 
    267                                     SelectedValue="{Binding Path=mm_df_ObjectDataTypeId, Mode=TwoWay}" 
    268                                     HorizontalAlignment="Left" 
    269                                     Width="200" 
    270                                     IsEnabled="False" 
    271                                     > 
    272                                     <i:Interaction.Behaviors> 
    273                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsObjectDataTypes" /> 
    274                                     </i:Interaction.Behaviors> 
    275                                 </input:RadComboBox> 
    276                             </dc:DataField> 
    277                             <dc:DataField Label="Caption"
    278                                 <TextBox Text="{Binding mm_df_Caption, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
    279                             </dc:DataField> 
    280                         </StackPanel> 
    281                         <StackPanel dc:DataField.IsFieldGroup="True"
    282                             <dc:DataField Label="Description"
    283                                 <TextBox Text="{Binding mm_df_Description, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
    284                             </dc:DataField> 
    285                             <dc:DataField Label="ToolTip"
    286                                 <TextBox Text="{Binding mm_df_ToolTip, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
    287                             </dc:DataField> 
    288                             <dc:DataField Label="Is ReadOnly"
    289                                 <CheckBox IsChecked="{Binding mm_df_IsReadOnly, Mode=TwoWay}" /> 
    290                             </dc:DataField> 
    291                             <dc:DataField Label="ItemsSource Table"
    292                                 <input:RadComboBox 
    293                                     DisplayMemberPath="mm_dt_FriendlyName" 
    294                                     SelectedValuePath="mm_dt_DataTableIdent" 
    295                                     SelectedValue="{Binding Path=mm_df_ItemsSourceTableId, Mode=TwoWay}" 
    296                                     HorizontalAlignment="Left" 
    297                                     Width="200" 
    298                                     IsEnabled="False" 
    299                                     > 
    300                                     <i:Interaction.Behaviors> 
    301                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
    302                                     </i:Interaction.Behaviors> 
    303                                 </input:RadComboBox> 
    304                             </dc:DataField> 
    305                             <dc:DataField Label="Is Display Member"
    306                                 <CheckBox IsChecked="{Binding mm_df_IsDisplayMember, Mode=TwoWay}" IsEnabled="False" /> 
    307                             </dc:DataField> 
    308                             <dc:DataField Label="Display Member Order"
    309                                 <TextBox Text="{Binding mm_df_DisplayMemberOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    310                             </dc:DataField> 
    311                             <dc:DataField Label="Is Value Member"
    312                                 <CheckBox IsChecked="{Binding mm_df_IsValueMember, Mode=TwoWay}" IsEnabled="False" /> 
    313                             </dc:DataField> 
    314                             <dc:DataField Label="Field Order"
    315                                 <TextBox Text="{Binding mm_df_FieldOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    316                             </dc:DataField> 
    317                             <dc:DataField Label="Data Format Type"
    318                                 <input:RadComboBox 
    319                                     DisplayMemberPath="mm_xdft_Name" 
    320                                     SelectedValuePath="mm_xdft_DataFormatTypeIdent" 
    321                                     SelectedValue="{Binding Path=mm_df_DataFormatTypeId, Mode=TwoWay}" 
    322                                     HorizontalAlignment="Left" 
    323                                     Width="200" 
    324                                     IsEnabled="False" 
    325                                     > 
    326                                     <i:Interaction.Behaviors> 
    327                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataFormatTypes" /> 
    328                                     </i:Interaction.Behaviors> 
    329                                 </input:RadComboBox> 
    330                             </dc:DataField> 
    331                             <dc:DataField Label="Custom Data Format"
    332                                 <TextBox Text="{Binding mm_df_CustomDataFormat, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
    333                             </dc:DataField> 
    334                             <dc:DataField Label="Encrypt Column"
    335                                 <CheckBox IsChecked="{Binding mm_df_EncryptColumn, Mode=TwoWay}" IsEnabled="False" /> 
    336                             </dc:DataField> 
    337                             <dc:DataField Label="Audit Field Changes"
    338                                 <CheckBox IsChecked="{Binding mm_df_AuditFieldChanges, Mode=TwoWay}" IsEnabled="False" /> 
    339                             </dc:DataField> 
    340                             <dc:DataField Label="Audit Sequence"
    341                                 <TextBox Text="{Binding mm_df_AuditSequence, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
    342                             </dc:DataField> 
    343                         </StackPanel> 
    344                     </StackPanel> 
    345                 </DataTemplate> 
    346             </dc:DataForm.ReadOnlyTemplate> 
    347  
    348             <dc:DataForm.EditTemplate> 
    349                 <DataTemplate> 
    350                     <StackPanel Orientation="Horizontal"
    351                         <StackPanel dc:DataField.IsFieldGroup="True"
    352                             <dc:DataField Label="Data Table"
    353                                 <input:RadComboBox 
    354                                         DisplayMemberPath="mm_dt_FriendlyName" 
    355                                         SelectedValuePath="mm_dt_DataTableIdent" 
    356                                         SelectedValue="{Binding Path=mm_df_DataTableId, Mode=TwoWay}" 
    357                                         HorizontalAlignment="Left" 
    358                                         Width="200"
    359                                     <i:Interaction.Behaviors> 
    360                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
    361                                     </i:Interaction.Behaviors> 
    362                                 </input:RadComboBox> 
    363                             </dc:DataField> 
    364                             <dc:DataField Label="Field Identity" IsReadOnly="True"
    365                                 <TextBox Text="{Binding mm_df_DataFieldIdent, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    366                             </dc:DataField> 
    367                             <dc:DataField Label="Field Name"
    368                                 <TextBox Text="{Binding mm_df_FieldName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
    369                             </dc:DataField> 
    370                             <dc:DataField Label="Friendly Name"
    371                                 <TextBox Text="{Binding mm_df_FriendlyName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
    372                             </dc:DataField> 
    373                             <dc:DataField Label="Default Value"
    374                                 <TextBox Text="{Binding mm_df_DefaultValue, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
    375                             </dc:DataField> 
    376                             <dc:DataField Label="Is Primary"
    377                                 <CheckBox IsChecked="{Binding mm_df_IsPrimary, Mode=TwoWay}" /> 
    378                             </dc:DataField> 
    379                             <dc:DataField Label="Is Identity"
    380                                 <CheckBox IsChecked="{Binding mm_df_IsIdentity, Mode=TwoWay}" /> 
    381                             </dc:DataField> 
    382                             <dc:DataField Label="Allow Nulls"
    383                                 <CheckBox IsChecked="{Binding mm_df_AllowNulls, Mode=TwoWay}" /> 
    384                             </dc:DataField> 
    385                             <dc:DataField Label="SQL Data Type"
    386                                 <input:RadComboBox 
    387                                         DisplayMemberPath="mm_xsdt_Name" 
    388                                         SelectedValuePath="mm_xsdt_SqlDataTypeIdent" 
    389                                         SelectedValue="{Binding Path=mm_df_SqlDataTypeId, Mode=TwoWay}" 
    390                                         HorizontalAlignment="Left" 
    391                                         Width="200"
    392                                     <i:Interaction.Behaviors> 
    393                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsSqlDataTypes" /> 
    394                                     </i:Interaction.Behaviors> 
    395                                 </input:RadComboBox> 
    396                             </dc:DataField> 
    397                             <dc:DataField Label="Length"
    398                                 <TextBox Text="{Binding mm_df_Length, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    399                             </dc:DataField> 
    400                             <dc:DataField Label="Precision"
    401                                 <TextBox Text="{Binding mm_df_Precision, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    402                             </dc:DataField> 
    403                             <dc:DataField Label="Scale"
    404                                 <TextBox Text="{Binding mm_df_Scale, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    405                             </dc:DataField> 
    406                             <dc:DataField Label="Object Data Type"
    407                                 <input:RadComboBox 
    408                                         DisplayMemberPath="mm_xodt_Name" 
    409                                         SelectedValuePath="mm_xodt_ObjectDataTypeIdent" 
    410                                         SelectedValue="{Binding Path=mm_df_ObjectDataTypeId, Mode=TwoWay}" 
    411                                         HorizontalAlignment="Left" 
    412                                         Width="200"
    413                                     <i:Interaction.Behaviors> 
    414                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsObjectDataTypes" /> 
    415                                     </i:Interaction.Behaviors> 
    416                                 </input:RadComboBox> 
    417                             </dc:DataField> 
    418                             <dc:DataField Label="Caption"
    419                                 <TextBox Text="{Binding mm_df_Caption, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
    420                             </dc:DataField> 
    421                         </StackPanel> 
    422                         <StackPanel dc:DataField.IsFieldGroup="True"
    423                             <dc:DataField Label="Description"
    424                                 <TextBox Text="{Binding mm_df_Description, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
    425                             </dc:DataField> 
    426                             <dc:DataField Label="ToolTip"
    427                                 <TextBox Text="{Binding mm_df_ToolTip, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
    428                             </dc:DataField> 
    429                             <dc:DataField Label="Is ReadOnly"
    430                                 <CheckBox IsChecked="{Binding mm_df_IsReadOnly, Mode=TwoWay}" /> 
    431                             </dc:DataField> 
    432                             <dc:DataField Label="ItemsSource Table"
    433                                 <input:RadComboBox 
    434                                         DisplayMemberPath="mm_dt_FriendlyName" 
    435                                         SelectedValuePath="mm_dt_DataTableIdent" 
    436                                         SelectedValue="{Binding Path=mm_df_ItemsSourceTableId, Mode=TwoWay}" 
    437                                         HorizontalAlignment="Left" 
    438                                         Width="200"
    439                                     <i:Interaction.Behaviors> 
    440                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
    441                                     </i:Interaction.Behaviors> 
    442                                 </input:RadComboBox> 
    443                             </dc:DataField> 
    444                             <dc:DataField Label="Is Display Member"
    445                                 <CheckBox IsChecked="{Binding mm_df_IsDisplayMember, Mode=TwoWay}" /> 
    446                             </dc:DataField> 
    447                             <dc:DataField Label="Display Member Order"
    448                                 <TextBox Text="{Binding mm_df_DisplayMemberOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    449                             </dc:DataField> 
    450                             <dc:DataField Label="Is Value Member"
    451                                 <CheckBox IsChecked="{Binding mm_df_IsValueMember, Mode=TwoWay}" /> 
    452                             </dc:DataField> 
    453                             <dc:DataField Label="Field Order"
    454                                 <TextBox Text="{Binding mm_df_FieldOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    455                             </dc:DataField> 
    456                             <dc:DataField Label="Data Format Type"
    457                                 <input:RadComboBox 
    458                                         DisplayMemberPath="mm_xdft_Name" 
    459                                         SelectedValuePath="mm_xdft_DataFormatTypeIdent" 
    460                                         SelectedValue="{Binding Path=mm_df_DataFormatTypeId, Mode=TwoWay}" 
    461                                         HorizontalAlignment="Left" 
    462                                         Width="200"
    463                                     <i:Interaction.Behaviors> 
    464                                         <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataFormatTypes" /> 
    465                                     </i:Interaction.Behaviors> 
    466                                 </input:RadComboBox> 
    467                             </dc:DataField> 
    468                             <dc:DataField Label="Custom Data Format"
    469                                 <TextBox Text="{Binding mm_df_CustomDataFormat, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
    470                             </dc:DataField> 
    471                             <dc:DataField Label="Encrypt Column"
    472                                 <CheckBox IsChecked="{Binding mm_df_EncryptColumn, Mode=TwoWay}" /> 
    473                             </dc:DataField> 
    474                             <dc:DataField Label="Audit Field Changes"
    475                                 <CheckBox IsChecked="{Binding mm_df_AuditFieldChanges, Mode=TwoWay}" /> 
    476                             </dc:DataField> 
    477                             <dc:DataField Label="Audit Sequence"
    478                                 <TextBox Text="{Binding mm_df_AuditSequence, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
    479                             </dc:DataField> 
    480                         </StackPanel> 
    481                     </StackPanel> 
    482                 </DataTemplate> 
    483             </dc:DataForm.EditTemplate> 
    484         </lc:DataForm> 
    485  
    486  
    487         <controls:GridSplitter Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Stretch"  
    488                                Width="5" Background="#FF777474"  
    489                                Margin="0,5,0,5"/> 
    490  
    491  
    492     </Grid> 
    493 </inf:ViewBase> 
    494  

    Let me know if you have any questions.

    Matt
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Sep 2009 Link to this post

    Hello Matt,

    I created a simple application that successfuly reproduces the problem you are getting. I figured that the exception could be thrown when the combo box cannot find a value to select. If you uncomment line 36 in DataSourceBehavior.cs, the application will work as expected. I will try to explain the reason for this problem:
    - initially RadComboBox does not have items. They come with some delay because they are retrieved from a web service. In my application I use DispatcherTimer to simulate this.
    - when RadComboBox does not have items, but its SelectedValue is set, the control will keep this value until its Items collection is changed. When the Items collection changes for the first time, RadComboBox will try to select an item with value, equal to SelectedValue. If there is no such item, it sets SelectedValue/SelectedItem = null, SelectedIndex = -1. I think that this is the expected behavior. In this case, in the attached application, a cast exception is thrown, that triggers the validation.

    The problem in your application could be caused by two things:
    1) The SelectedValue is missing from the items that are returned by the service. I suppose that this is not the problem, bacause I guess you are binding foreign keys.
    2) The ItemsSourceToDomainDataSourceBehavior could work this way: when set, it sets a new ObservableCollection<T> as ItemsSource on the specified ItemsControl, later when the data comes it adds the values one by one to that observable collection. The first add throws the exception and triggers the validation, unless the first item is the same as SelectedValue.

    The solution of the first case is obvious. For the second case - I was unable to find Core.Infrastructure.Silverlight assembly in my SDKs folder, so I guess it is custom made. If it is, I would recommend changing the way it sets ItemsSource - it should be at once, not one item at a time.

    There is one thing that I wasn't able to reproduce - validation error + properly selected value in RadComboBox.

    There might be other scenarios, but this is what I was able to find out for now. If you think that I might be missing something, please, let me know. If there is anything that I could help, please, do not hesitate to write again.

    Best wishes,
    Valeri Hristov
    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.
Back to Top
DevCraft banner