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

Selecting Linq to SQL parent using combo

1 Answer 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pelle
Top achievements
Rank 1
Pelle asked on 09 Feb 2011, 09:19 PM
Dear Telerik forum :)

I have a parent-child relation between two business objects (defined in Linq to SQL):
  - Parent: TransactionAccount
  - Child: Transaction

I want to show all transactions in a grid. Each transaction shall have a combobox displaying all available transactions. I also want to use the built in grouping and sorting functionality. After a bit of struggling with different options I came up with the following solution.

<telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding TransactionAccount.Name, Mode=OneWay}" Header="AccountName">
        <telerik:GridViewDataColumn.CellEditTemplate>
            <DataTemplate>
                <ComboBox
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadGridView}, Path=DataContext}"
                    DisplayMemberPath="Name"
                    IsEditable="False"
                    IsReadOnly="True"
                    ItemsSource="{Binding TransactionAccounts}"
                    SelectedItem="{Binding CurrentTransaction.TransactionAccount, Mode=TwoWay}" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellEditTemplate>
        <telerik:GridViewDataColumn.AggregateFunctions>
            <Data:CountFunction Caption="Count: " />
        </telerik:GridViewDataColumn.AggregateFunctions>
    </telerik:GridViewDataColumn>

This seems to work fine but in some particular cases (that I just cannot put my finger on) the parent Name is changed. So if I have two accounts Account1 and Account2, suddenly both have the same name.

ISSUE 1: So my question is: is this really the right approach? If so why does the binding update a property on my BO? I have tried every possible way to prevent that (IsEditable, IsReadOnly etc). 

ISSUE 2: Another issue is that when I have the combo open on the last row and press Enter the focus goes "somewhere else" and the only way to resume navigation with the keyboard is to click on the application.

Thanks for any input!

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Feb 2011, 12:49 PM
Hi Pelle,

Usually, this behavior is observed in case one and the same object is bound to in both rows. However, in order to provide you with a valuable solution, I would need a bit more information about the implementations of the business objects both for the source of the grid and the RadComboBox. On the other hand, would it not be more appropriate for your scenario to use the built-in GridViewComboBoxColumn ? 
As far as the second issue is concerned, we would need a bit more time for investigating the case and the cause for it.

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Pelle
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or