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

How to set a default value which is bound to another value for the combobox in datagrid

1 Answer 19 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Tai asked on 17 Aug 2010, 10:08 PM


I have a datagrid which has one combobox column.

-the itemsource of the datagrid will be bound to the data from the database through RIA WCF

-the itemsource of the combobox which is inside the datagrid will be bound to the ListFinancialAccountType property which is a collection of Financial Account Types (also retrieve through RIA WCF).

I can show the list of all of the available Account Type Name for the combobox. However, I can't set the default value for the combobox which should be matched with the value of each row in the datagrid

For example: the value of the combobox will tell us what type of the financial account is(Asset, income,..) . However, its real value in the row of the datagrid is an integer type(FinancialAccountTypeId) but i want it to be displayed as either "Asset", "Income",... So i need to look up on the Financial Account Type List(which will be retrieved through RIA WCF). The FinancialAccountType has FinancialAccountTypeId and AccountTypeName properties.

So on the rows of the datagrid, the combobox will display "Asset", "Income",....   instead of 1,2,... .

For my FinancialAccount: properties are



                         FinancialAccountTypeId              (example: 1, 2,...)

                         FinancialAccountType                   --->navigation property

For my FinancialAccountType: properties are

                          AccountTypeName                     (example: "Asset", ...)

                          FinancialAccountTypeId              (example: 1,2,...)

                            FinancialAccounts                    ---> navigation property

This is my XAML code

<Grid x:Name="LayoutRoot">
            <financial:Financial_Account_Types x:Key="FinancialAccountTypes"/>
        <sdk:DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left"  Margin="112,83,0,0" Name="financialAccountDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="400">
                <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">
                            <ComboBox  ItemsSource="{Binding ListFinancialAccountType, Source={StaticResource FinancialAccountTypes},Mode=TwoWay}"
                                        SelectedValue="{Binding FinancialAccountTypeId, Mode=TwoWay}"

This is my Code Behind

public partial class Financial_Accounts : Page
        public Financial_Accounts()
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
            FinancialAccountContext financial_ctx = new FinancialAccountContext();
            financialAccountDataGrid.ItemsSource = financial_ctx.FinancialAccounts;
    public class Financial_Account_Types : ObservableCollection<FinancialAccountType>
        public EntitySet<FinancialAccountType> ListFinancialAccountType
                FinancialAccountContext financial_ctx = new FinancialAccountContext();
                return financial_ctx.FinancialAccountTypes;

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 19 Aug 2010, 11:26 AM
Hello Tai,

Thank you for contacting us.

The code looks OK, and it should work as expected. Attached I am sending you a sample project close to your scenario, which works fine. If you still experience difficulties with the Microsoft's ComboBox please write in the forums. There you will receive more accurate answers to your inquiries.

Please let us know if you have any other questions regarding our controls.

the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question