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

Binding Error for RadComboBox in DataForm

5 Answers 506 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matt Duffield
Top achievements
Rank 1
Matt Duffield asked on 29 Aug 2009, 02:37 AM
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

5 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 31 Aug 2009, 03:48 PM
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.
0
Matt Duffield
Top achievements
Rank 1
answered on 31 Aug 2009, 06:29 PM
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
0
Valeri Hristov
Telerik team
answered on 01 Sep 2009, 10:48 AM
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.
0
Matt Duffield
Top achievements
Rank 1
answered on 01 Sep 2009, 02:26 PM
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:
<inf:ViewBase 
    x:Class="CodeMaster.MetaModel.Silverlight.DataFieldView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:inf="clr-namespace:Core.Infrastructure.Silverlight.UI.View;assembly=Core.Infrastructure.Silverlight" 
    xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls" 
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"    
    xmlns:dc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation" 
    xmlns:trg="clr-namespace:Core.Infrastructure.Silverlight.Triggers;assembly=Core.Infrastructure.Silverlight" 
    xmlns:beh="clr-namespace:Core.Infrastructure.Silverlight.Behaviors;assembly=Core.Infrastructure.Silverlight" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:lc="clr-namespace:Core.Infrastructure.Silverlight.UI.Controls;assembly=Core.Infrastructure.Silverlight" 
    xmlns:domain="clr-namespace:CodeMaster.Data.Web;assembly=CodeMaster.Data.Silverlight" 
    xmlns:input="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
    > 
    <inf:ViewBase.DataContext> 
        <Binding Path="DataFieldViewModel" Source="{StaticResource MetaModelModule}" /> 
    </inf:ViewBase.DataContext> 
    <Grid x:Name="LayoutRoot" Background="White"
        <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
        <riaControls:DomainDataSource  
            x:Name="ddsDataTables" 
            QueryName="GetMm_dt_DataTables" 
            AutoLoad="True" 
            LoadSize="20" 
            > 
            <riaControls:DomainDataSource.DomainContext> 
                <domain:MetaModelDomainContext /> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.SortDescriptors> 
                <riaData:SortDescriptor PropertyPath="mm_dt_FriendlyName" Direction="Ascending" /> 
            </riaControls:DomainDataSource.SortDescriptors> 
        </riaControls:DomainDataSource> 
        <riaControls:DomainDataSource  
            x:Name="dds" 
            DomainContext="{Binding DomainContext}" 
            QueryName="GetMm_df_DataFields" 
            AutoLoad="True" 
            > 
            <riaControls:DomainDataSource.SortDescriptors> 
                <riaData:SortDescriptor PropertyPath="mm_dt_DataTable.mm_dt_FriendlyName" Direction="Ascending" /> 
                <riaData:SortDescriptor PropertyPath="mm_df_FieldOrder" Direction="Ascending" /> 
            </riaControls:DomainDataSource.SortDescriptors> 
            <riaControls:DomainDataSource.FilterDescriptors> 
                <riaData:FilterDescriptorCollection> 
                    <riaData:FilterDescriptor PropertyPath="mm_df_DataTableId" 
                                              Operator="IsEqualTo"
                        <riaData:ControlParameter PropertyName="SelectedItem.mm_dt_DataTableIdent" 
                                                  RefreshEventName="SelectionChanged" 
                                                  ControlName="dgTableFilter" /> 
                    </riaData:FilterDescriptor> 
                </riaData:FilterDescriptorCollection> 
            </riaControls:DomainDataSource.FilterDescriptors> 
        </riaControls:DomainDataSource> 
        <riaControls:DomainDataSource  
            x:Name="ddsDataFormatTypes" 
            DomainContext="{Binding DomainContext}" 
            QueryName="GetMm_xdft_DataFormatTypes" 
            AutoLoad="True" 
            > 
            <riaControls:DomainDataSource.SortDescriptors> 
                <riaData:SortDescriptor PropertyPath="mm_xdft_Name" Direction="Ascending" /> 
            </riaControls:DomainDataSource.SortDescriptors> 
        </riaControls:DomainDataSource> 
        <riaControls:DomainDataSource  
            x:Name="ddsObjectDataTypes" 
            DomainContext="{Binding DomainContext}" 
            QueryName="GetMm_xodt_ObjectDataTypes" 
            AutoLoad="True" 
            > 
            <riaControls:DomainDataSource.SortDescriptors> 
                <riaData:SortDescriptor PropertyPath="mm_xodt_Name" Direction="Ascending" /> 
            </riaControls:DomainDataSource.SortDescriptors> 
        </riaControls:DomainDataSource> 
        <riaControls:DomainDataSource  
            x:Name="ddsSqlDataTypes" 
            DomainContext="{Binding DomainContext}" 
            QueryName="GetMm_xsdt_SqlDataTypes" 
            AutoLoad="True" 
            > 
            <riaControls:DomainDataSource.SortDescriptors> 
                <riaData:SortDescriptor PropertyPath="mm_xsdt_Name" Direction="Ascending" /> 
            </riaControls:DomainDataSource.SortDescriptors> 
        </riaControls:DomainDataSource> 
 
 
        <lc:HeaderedContentControl 
            x:Name="hccDataTableCollection" 
            Grid.Column="0" 
            FooterVisible="True" 
            Margin="5" 
            ItemsSource="{Binding ElementName=ddsDataTables, Path=Data}" 
            > 
            <lc:HeaderedContentControl.HeaderTemplate> 
                <DataTemplate> 
                    <Grid Background="{StaticResource Header_BackgroundGradient}"
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="Auto" /> 
                            <ColumnDefinition Width="Auto" /> 
                        </Grid.ColumnDefinitions> 
                        <TextBlock Text="Tables" Style="{StaticResource TextBlockH1Style}"/> 
                    </Grid> 
                </DataTemplate> 
            </lc:HeaderedContentControl.HeaderTemplate> 
 
            <data:DataGrid 
                    x:Name="dgTableFilter" 
                    ItemsSource="{Binding ElementName=ddsDataTables, Path=Data}" 
                    SelectionMode="Single" 
                    AutoGenerateColumns="False" 
                    IsReadOnly="True" 
                    > 
                <data:DataGrid.Columns> 
                    <data:DataGridTextColumn Header="Table Name" Binding="{Binding mm_dt_FriendlyName}" /> 
                </data:DataGrid.Columns> 
            </data:DataGrid> 
 
            <lc:HeaderedContentControl.FooterTemplate> 
                <DataTemplate> 
                    <Grid Margin="7,1,0,1"
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="Auto" /> 
                            <ColumnDefinition Width="Auto"/> 
                        </Grid.ColumnDefinitions> 
                        <TextBlock Text="Count:" VerticalAlignment="Center" /> 
                        <TextBox Grid.Column="1" Text="{Binding ElementName=hccDataTableCollection, Path=Count}" IsReadOnly="True" VerticalAlignment="Center" Style="{StaticResource TextBoxStyle}" Width="50" Margin="2,0,0,5"  /> 
                    </Grid> 
                </DataTemplate> 
            </lc:HeaderedContentControl.FooterTemplate> 
        </lc:HeaderedContentControl> 
 
        <lc:HeaderedContentControl 
            x:Name="hccDataFieldCollection" 
            Grid.Column="1" 
            Margin="5" 
            ItemsSource="{Binding ElementName=dds, Path=Data}" 
            > 
            <lc:HeaderedContentControl.HeaderTemplate> 
                <DataTemplate> 
                    <Grid Background="{StaticResource Header_BackgroundGradient}"
                        <TextBlock Text="Data Fields" Style="{StaticResource TextBlockH1Style}"/> 
                    </Grid> 
                </DataTemplate> 
            </lc:HeaderedContentControl.HeaderTemplate> 
 
            <data:DataGrid 
                        x:Name="dgDataFields" 
                        ItemsSource="{Binding ElementName=dds, Path=Data}" 
                        SelectedItem="{Binding CurrentItem, Mode=TwoWay}" 
                        SelectionMode="Single" 
                        AutoGenerateColumns="False" 
                        IsReadOnly="True" 
                        > 
                <data:DataGrid.Columns> 
                    <data:DataGridTextColumn Header="Field Name" Binding="{Binding mm_df_FriendlyName}" /> 
                </data:DataGrid.Columns> 
            </data:DataGrid> 
 
            <lc:HeaderedContentControl.FooterTemplate> 
                <DataTemplate> 
                    <Grid Margin="7,1,0,1"
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="Auto" /> 
                            <ColumnDefinition Width="Auto"/> 
                        </Grid.ColumnDefinitions> 
                        <TextBlock Text="Count:" VerticalAlignment="Center" /> 
                        <TextBox Grid.Column="1" Text="{Binding ElementName=hccDataFieldCollection, Path=Count}" IsReadOnly="True" VerticalAlignment="Center" Style="{StaticResource TextBoxStyle}" Width="50" Margin="2,0,0,5"  /> 
                    </Grid> 
                </DataTemplate> 
            </lc:HeaderedContentControl.FooterTemplate> 
        </lc:HeaderedContentControl> 
 
 
        <lc:DataForm 
                x:Name="dfDetail" 
                Grid.Column="2" 
                AutoGenerateFields="False" 
                ItemsSource="{Binding ElementName=dds, Path=Data}" 
                Header="Data Fields" 
                Margin="10,5,5,5" 
                AutoCommit="False" 
                AutoEdit="False" 
                > 
            <i:Interaction.Triggers> 
                <i:EventTrigger EventName="EditEnded"
                    <trg:ExecuteCommandTrigger TargetCommand="ActionCommand" UserState="EditEnded" /> 
                </i:EventTrigger> 
                <i:EventTrigger EventName="DeletingItem"
                    <trg:ExecuteCommandTrigger TargetCommand="ActionCommand" UserState="DeletingItem" /> 
                </i:EventTrigger> 
            </i:Interaction.Triggers> 
 
 
            <dc:DataForm.ReadOnlyTemplate> 
                <DataTemplate> 
                    <StackPanel Orientation="Horizontal"
                        <StackPanel dc:DataField.IsFieldGroup="True"
                            <dc:DataField Label="Data Table"
                                <input:RadComboBox 
                                    DisplayMemberPath="mm_dt_FriendlyName" 
                                    SelectedValuePath="mm_dt_DataTableIdent" 
                                    SelectedValue="{Binding Path=mm_df_DataTableId, Mode=TwoWay}" 
                                    HorizontalAlignment="Left" 
                                    Width="200" 
                                    IsEnabled="False" 
                                    > 
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Identity" IsReadOnly="True"
                                <TextBox Text="{Binding mm_df_DataFieldIdent, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Name"
                                <TextBox Text="{Binding mm_df_FieldName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Friendly Name"
                                <TextBox Text="{Binding mm_df_FriendlyName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Default Value"
                                <TextBox Text="{Binding mm_df_DefaultValue, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Primary"
                                <CheckBox IsChecked="{Binding mm_df_IsPrimary, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Identity"
                                <CheckBox IsChecked="{Binding mm_df_IsIdentity, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Allow Nulls"
                                <CheckBox IsChecked="{Binding mm_df_AllowNulls, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="SQL Data Type"
                                <input:RadComboBox 
                                    DisplayMemberPath="mm_xsdt_Name" 
                                    SelectedValuePath="mm_xsdt_SqlDataTypeIdent" 
                                    SelectedValue="{Binding Path=mm_df_SqlDataTypeId, Mode=TwoWay}" 
                                    HorizontalAlignment="Left" 
                                    Width="200" 
                                    IsEnabled="False" 
                                    > 
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsSqlDataTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Length"
                                <TextBox Text="{Binding mm_df_Length, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Precision"
                                <TextBox Text="{Binding mm_df_Precision, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Scale"
                                <TextBox Text="{Binding mm_df_Scale, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Object Data Type"
                                <input:RadComboBox 
                                    DisplayMemberPath="mm_xodt_Name" 
                                    SelectedValuePath="mm_xodt_ObjectDataTypeIdent" 
                                    SelectedValue="{Binding Path=mm_df_ObjectDataTypeId, Mode=TwoWay}" 
                                    HorizontalAlignment="Left" 
                                    Width="200" 
                                    IsEnabled="False" 
                                    > 
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsObjectDataTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Caption"
                                <TextBox Text="{Binding mm_df_Caption, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                        </StackPanel> 
                        <StackPanel dc:DataField.IsFieldGroup="True"
                            <dc:DataField Label="Description"
                                <TextBox Text="{Binding mm_df_Description, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="ToolTip"
                                <TextBox Text="{Binding mm_df_ToolTip, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is ReadOnly"
                                <CheckBox IsChecked="{Binding mm_df_IsReadOnly, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="ItemsSource Table"
                                <input:RadComboBox 
                                    DisplayMemberPath="mm_dt_FriendlyName" 
                                    SelectedValuePath="mm_dt_DataTableIdent" 
                                    SelectedValue="{Binding Path=mm_df_ItemsSourceTableId, Mode=TwoWay}" 
                                    HorizontalAlignment="Left" 
                                    Width="200" 
                                    IsEnabled="False" 
                                    > 
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Display Member"
                                <CheckBox IsChecked="{Binding mm_df_IsDisplayMember, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Display Member Order"
                                <TextBox Text="{Binding mm_df_DisplayMemberOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Value Member"
                                <CheckBox IsChecked="{Binding mm_df_IsValueMember, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Order"
                                <TextBox Text="{Binding mm_df_FieldOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Data Format Type"
                                <input:RadComboBox 
                                    DisplayMemberPath="mm_xdft_Name" 
                                    SelectedValuePath="mm_xdft_DataFormatTypeIdent" 
                                    SelectedValue="{Binding Path=mm_df_DataFormatTypeId, Mode=TwoWay}" 
                                    HorizontalAlignment="Left" 
                                    Width="200" 
                                    IsEnabled="False" 
                                    > 
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataFormatTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Custom Data Format"
                                <TextBox Text="{Binding mm_df_CustomDataFormat, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Encrypt Column"
                                <CheckBox IsChecked="{Binding mm_df_EncryptColumn, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Audit Field Changes"
                                <CheckBox IsChecked="{Binding mm_df_AuditFieldChanges, Mode=TwoWay}" IsEnabled="False" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Audit Sequence"
                                <TextBox Text="{Binding mm_df_AuditSequence, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" IsReadOnly="True" /> 
                            </dc:DataField> 
                        </StackPanel> 
                    </StackPanel> 
                </DataTemplate> 
            </dc:DataForm.ReadOnlyTemplate> 
 
            <dc:DataForm.EditTemplate> 
                <DataTemplate> 
                    <StackPanel Orientation="Horizontal"
                        <StackPanel dc:DataField.IsFieldGroup="True"
                            <dc:DataField Label="Data Table"
                                <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> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Identity" IsReadOnly="True"
                                <TextBox Text="{Binding mm_df_DataFieldIdent, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Name"
                                <TextBox Text="{Binding mm_df_FieldName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Friendly Name"
                                <TextBox Text="{Binding mm_df_FriendlyName, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Default Value"
                                <TextBox Text="{Binding mm_df_DefaultValue, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Primary"
                                <CheckBox IsChecked="{Binding mm_df_IsPrimary, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Identity"
                                <CheckBox IsChecked="{Binding mm_df_IsIdentity, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Allow Nulls"
                                <CheckBox IsChecked="{Binding mm_df_AllowNulls, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="SQL Data Type"
                                <input:RadComboBox 
                                        DisplayMemberPath="mm_xsdt_Name" 
                                        SelectedValuePath="mm_xsdt_SqlDataTypeIdent" 
                                        SelectedValue="{Binding Path=mm_df_SqlDataTypeId, Mode=TwoWay}" 
                                        HorizontalAlignment="Left" 
                                        Width="200"
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsSqlDataTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Length"
                                <TextBox Text="{Binding mm_df_Length, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Precision"
                                <TextBox Text="{Binding mm_df_Precision, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Scale"
                                <TextBox Text="{Binding mm_df_Scale, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Object Data Type"
                                <input:RadComboBox 
                                        DisplayMemberPath="mm_xodt_Name" 
                                        SelectedValuePath="mm_xodt_ObjectDataTypeIdent" 
                                        SelectedValue="{Binding Path=mm_df_ObjectDataTypeId, Mode=TwoWay}" 
                                        HorizontalAlignment="Left" 
                                        Width="200"
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsObjectDataTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Caption"
                                <TextBox Text="{Binding mm_df_Caption, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
                            </dc:DataField> 
                        </StackPanel> 
                        <StackPanel dc:DataField.IsFieldGroup="True"
                            <dc:DataField Label="Description"
                                <TextBox Text="{Binding mm_df_Description, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="ToolTip"
                                <TextBox Text="{Binding mm_df_ToolTip, Mode=TwoWay}" Style="{StaticResource TextBoxStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is ReadOnly"
                                <CheckBox IsChecked="{Binding mm_df_IsReadOnly, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="ItemsSource Table"
                                <input:RadComboBox 
                                        DisplayMemberPath="mm_dt_FriendlyName" 
                                        SelectedValuePath="mm_dt_DataTableIdent" 
                                        SelectedValue="{Binding Path=mm_df_ItemsSourceTableId, Mode=TwoWay}" 
                                        HorizontalAlignment="Left" 
                                        Width="200"
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataTables" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Display Member"
                                <CheckBox IsChecked="{Binding mm_df_IsDisplayMember, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Display Member Order"
                                <TextBox Text="{Binding mm_df_DisplayMemberOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Is Value Member"
                                <CheckBox IsChecked="{Binding mm_df_IsValueMember, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Field Order"
                                <TextBox Text="{Binding mm_df_FieldOrder, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Data Format Type"
                                <input:RadComboBox 
                                        DisplayMemberPath="mm_xdft_Name" 
                                        SelectedValuePath="mm_xdft_DataFormatTypeIdent" 
                                        SelectedValue="{Binding Path=mm_df_DataFormatTypeId, Mode=TwoWay}" 
                                        HorizontalAlignment="Left" 
                                        Width="200"
                                    <i:Interaction.Behaviors> 
                                        <beh:ItemsSourceToDomainDataSourceBehavior ControlName="ddsDataFormatTypes" /> 
                                    </i:Interaction.Behaviors> 
                                </input:RadComboBox> 
                            </dc:DataField> 
                            <dc:DataField Label="Custom Data Format"
                                <TextBox Text="{Binding mm_df_CustomDataFormat, Mode=TwoWay}" Style="{StaticResource TextBoxMediumStyle}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Encrypt Column"
                                <CheckBox IsChecked="{Binding mm_df_EncryptColumn, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Audit Field Changes"
                                <CheckBox IsChecked="{Binding mm_df_AuditFieldChanges, Mode=TwoWay}" /> 
                            </dc:DataField> 
                            <dc:DataField Label="Audit Sequence"
                                <TextBox Text="{Binding mm_df_AuditSequence, Mode=TwoWay}" Style="{StaticResource TextBoxShortStyle}" /> 
                            </dc:DataField> 
                        </StackPanel> 
                    </StackPanel> 
                </DataTemplate> 
            </dc:DataForm.EditTemplate> 
        </lc:DataForm> 
 
 
        <controls:GridSplitter Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Stretch"  
                               Width="5" Background="#FF777474"  
                               Margin="0,5,0,5"/> 
 
 
    </Grid> 
</inf:ViewBase> 
 

Let me know if you have any questions.

Matt
0
Valeri Hristov
Telerik team
answered on 04 Sep 2009, 02:38 PM
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.
Tags
ComboBox
Asked by
Matt Duffield
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Matt Duffield
Top achievements
Rank 1
Share this question
or