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

Problem when iserting new row to a DataTable bound GridView with dependent columns

1 Answer 235 Views
This is a migrated thread and some comments may be shown as answers.
Yuri P.
Top achievements
Rank 1
Yuri P. asked on 16 Jun 2010, 11:26 AM

I am using Telerik Controls for WPF Q3 2009 (2009.3.1314.35), .NET 3.5 SP1, Windows XP SP2. I have two problems.

I have a grid bound to a (strongly typed) DataTable which has two dependent columns (in my project they're bound to the same data but display it differently). My goal is to have one column update when another changes, meaning on CellEditEnded (preferably) or RowEditEned.

For example:
<telerik:RadGridView Name="RadGridView" AutoGenerateColumns="False">
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Product_Name}" Header="Product Name"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Product_Name}" Header="Product Name Again"/>

I want "Product Name Again" to refresh after "Product Name" is edited.

Searching through the forums and experimenting, I couldn't find a solution that completely works.
I should note that the same situation, but when binding to an ObservableCollection of CLR objects, works with no problem.

I tried the following:

When binding to DataTable.DefaultView, the dependent column is affected when UPDATING an existing row, but not when INSERTING a new row.
When inserting, the dependent column refreshes only after entering edit mode again and committing.

When binding directly to DataTable, updating works, but when inserting the new row visually disappears when the editing is finished. I implemented AddingNewDataItem and RowEditEnded to enable inserting.

I did something like this (assuming null is valid for all columns of the products table):
        private void RadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
            // _productsDataTable is a strongly typed reference to the DataTable
            var product = _productsDataTable.NewProductsRow();
            e.NewObject = product;

        private void RadGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
            if (e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert &&
                e.EditAction == Telerik.Windows.Controls.GridView.GridViewEditAction.Commit)
                _productsDataTable.AddProductsRow(e.NewData as ProductsRow);
(I also tried adding the row to the table in AddingNewDataItem instead of in RowEditEnded, but got the same result)

Do have any suggestions on what might work?


I have a grid ordered by a non-visible "priority" field, with CanUserReorderColumns=False. I'm unable to make the ordering refresh when the "priority" changes.

The grid has one column that looks something like this:

Change priority
   [+] [-]
   [+] [-]
   [+] [-]

If for example, the user clicks [+] on the second row, a command is invoked on a ViewModel class which changes the "priority" values of the first and second rows, so that after reordering the rows will swap places.

A requirement is that the user will always be able to click the buttons in one step, without needing to enter edit-mode first with F2/click etc.
To achieve this, I defined the buttons in the column's CellTemplate and prevented it from ever entering edit mode.

The problem is, after clicking the buttons, the underlying data changes but the grid isn't automatically reordered (which I guess is because the grid isn't aware of any edit action). The underlying data implements INotifyPropertyChanged.

I tried triggering reordering manually, but the buttons' OnClick/OnMouseUp events fire before their commands, so it had no effect.

Thanks in advance,

1 Answer, 1 is accepted

Sort by
Stefan Dobrev
Telerik team
answered on 21 Jun 2010, 08:14 AM
Hello Yuri P.,

Find my answers in order:
  1. I have tried your scenario with binding to a DataView and everything works as expected without any custom code. Please find my sample project attached to this forum thread.
  2. Please check this blog post which illustrates how to preserve the sorting when an edit is executed outside of the grid view control. You can use the same concept in your case as well.

Stefan Dobrev
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
Yuri P.
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Share this question