0

コンボボックス列が 1 つあるデータグリッドがあります。

- データグリッドの itemsource は、RIA WCF を介してデータベースからのデータにバインドされます

- データグリッド内にあるコンボボックスの itemsource は、金融口座タイプのコレクションである ListFinancialAccountType プロパティにバインドされます (これも RIA WCF から取得します)。

コンボボックスで使用可能なすべてのアカウント タイプ名のリストを表示できます。ただし、データグリッドの各行の値と一致する必要があるコンボボックスのデフォルト値を設定できません

例: コンボボックスの値は、金融口座のタイプが (資産、収入、..) であるかを示します。ただし、行の実際の値は整数型 (FinancialAccountTypeId) ですが、「資産」、「収入」のいずれかとして表示したいので、金融口座タイプ リスト (これはRIA WCF から取得できます)。FinancialAccountType には、FinancialAccountTypeId および AccountTypeName プロパティがあります。

したがって、データグリッドの行では、コンボボックスは 1,2,... の代わりに "Asset", "Income",.... を表示します。

私の FinancialAccount の場合: プロパティは

                      AccountDescription  

                      AccountNumber

                     FinancialAccountTypeId                  example: 1,2,...

                     FinancialAccountType                   --->navigation property

私の FinancialAccountType の場合: プロパティは

                      AccountTypeName                       example: "asset", ...

                      FinancialAccountTypeId                example: 1, 2...

                        FinancialAccounts                    ---> navigation property

私のコード ビハインドでは、金融口座の種類のリストも入力します。ここで読み込みの問題が発生するはずです。どんな入力でも大歓迎です

これが私のコードビハインドです

 public partial class Financial_Accounts : Page
{
    public Financial_Accounts()
    {
        InitializeComponent();
    }

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        FinancialAccountContext financial_ctx = new FinancialAccountContext();
        financial_ctx.Load(financial_ctx.GetFinancialAccountsQuery());
        financialAccountDataGrid.ItemsSource = financial_ctx.FinancialAccounts;

    }

}

public class Financial_Account_Types : ObservableCollection<FinancialAccountType>
{
    public EntitySet<FinancialAccountType> ListFinancialAccountType
    {
        get 
        {
            FinancialAccountContext financial_ctx = new FinancialAccountContext();
            financial_ctx.Load(financial_ctx.GetFinancialAccountTypesQuery());
            return financial_ctx.FinancialAccountTypes;
        }
    }
}

ここに私のXAMLがあります

 <Grid.Resources>
        <financial:Financial_Account_Types x:Key="FinancialAccountTypes"/>
    </Grid.Resources>
    <sdk:DataGrid AutoGenerateColumns="False" Height="159" HorizontalAlignment="Left" Name="financialAccountDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="280">
        <sdk:DataGrid.Columns>
            <sdk:DataGridTextColumn x:Name="accountDescriptionColumn" Binding="{Binding Path=AccountDescription}" Header="Account Name" Width="SizeToHeader" />
            <sdk:DataGridTextColumn x:Name="accountNumberColumn" Binding="{Binding Path=AccountNumber}" Header="Account Number" Width="SizeToHeader" />
            <sdk:DataGridTemplateColumn x:Name="financialAccountTypeIdColumn" Header="Account Type" Width="SizeToHeader">
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox  ItemsSource="{Binding ListFinancialAccountType, Source={StaticResource FinancialAccountTypes},Mode=TwoWay}"
                                    SelectedValue="{Binding FinancialAccountTypeId, Mode=TwoWay}"

                                  DisplayMemberPath="AccountTypeName"
                                  SelectedValuePath="FinancialAccountTypeId"
                                  />

                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>
4

1 に答える 1

0

Kyle McClellan ソリューションを見てください:
http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx

于 2010-09-07T20:05:33.007 に答える