I am trying to add a new item to the GridView. When the user tabs past the last column of the last row I'm inserting a new row and placing it in edit mode. I do this by handling the KeyDown event like this:
I also handle the AddingNewDataItem event to add a new object:
The problem is that I need the new object to be added to the underlying collection that is bound to the ItemsSource property of the GridView so that a number of event handlers can be hooked up to events on the OrderDetail object. (These events bubble up list / property change notifications to the parent Order object for such things as calculating the Order total, sales tax, etc.).
The new row is being added and it gets set into edit mode but when I modify data in the columns for Quantity and UnitPrice no events are being published because the OrderDetail object is not inserted into the collection (which does the job of hooking up the events).
I tried to add the object to the collection but then I get two new rows added to the GridView. What I would like to do is add the OrderDetail to the underlying collection so that event handlers get hooked up but then set the row into edit mode on the first column. Is this possible or is there some other way to approach this?
Thanks,
Dave
private void RadGridView_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab)
{
var grid = sender as RadGridView;
var currentItem = grid.CurrentItem as OrderDetail;
if ((currentItem != null) && (currentItem.IsValid))
{
grid.BeginInsert();
grid.CurrentColumn = grid.Columns[0];
}
else
{
e.Handled = true;
}
}
}
I also handle the AddingNewDataItem event to add a new object:
private void RadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
e.NewObject = OrderDetail.NewOrderDetail();
}
The problem is that I need the new object to be added to the underlying collection that is bound to the ItemsSource property of the GridView so that a number of event handlers can be hooked up to events on the OrderDetail object. (These events bubble up list / property change notifications to the parent Order object for such things as calculating the Order total, sales tax, etc.).
The new row is being added and it gets set into edit mode but when I modify data in the columns for Quantity and UnitPrice no events are being published because the OrderDetail object is not inserted into the collection (which does the job of hooking up the events).
I tried to add the object to the collection but then I get two new rows added to the GridView. What I would like to do is add the OrderDetail to the underlying collection so that event handlers get hooked up but then set the row into edit mode on the first column. Is this possible or is there some other way to approach this?
Thanks,
Dave