4 Answers, 1 is accepted
There are different possible scenarios when inserting a new row, so please share more details about your project and what exactly are you expecting as a result. Are you using the property of the grid ShowInsertRow or the method BeginInsert () ? Depending on the sorting state of the grid, the newly-added row may show up at different places, when being added. Do you want it to be selected after being inserted? Furthermore, share more information about the way your data and the way you are defining it in the project.
Maya
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.
private void PricingGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e) {
ProductPricing pricing = _productPricingList.AddNew();
e.NewObject = pricing;
}private void PricingGrid_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e) {
if (e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert) {
this.DataContext = _productPricingList.OrderBy(ps => ps.ProductId);
CollectionViewSource cvs = this.FindResource("cvs_pricing") as CollectionViewSource;
cvs.Source = this.DataContext;
PricingGrid.SelectedItem = e.NewData;
PricingGrid.ScrollIntoView(e.NewData);
}
}
I have prepared a small sample project using the code-snippet you sent and the newly-added row is selected as expected. However, there are a couple of issues here. Firstly, when inserting a new item using AddingNewDataItem event, the EditOperationType is "Edit". Thus for the same purpose you may use BeginningEdit event instead.
As for the visibility of the inserted item and the fact that it is not displayed in the grid, we would need more details about the way you are reproducing it. Are you using BeginInsert() or you are setting ShowInsertRow property to "True"?
I am sending you the sample project. Please feel free to change so that it meets your exact requirements and tell us how it goes.
Maya
the Telerik team
Bind your grid to a list at your page. The name of the list is Products
Define a key down event for the grid. When you bind the grid to a list with mode two way, you only have to insert a new item to the list. The grid gets it automatically
<
telerik:RadGridView
Margin
=
"5"
Grid.Row
=
"1"
Grid.Column
=
"0"
Grid.ColumnSpan
=
"2"
SelectionMode
=
"Single"
Name
=
"DataGridProducts"
Width
=
"Auto"
HorizontalAlignment
=
"Left"
ShowGroupPanel
=
"False"
KeyDown
=
"DataGridProducts_KeyDown"
VerticalAlignment
=
"Top"
CellEditEnded
=
"DataGridProducts_CellEditEnded"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PageFastProductAdd}},Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Path=Products}"
>
private DynaList<
Product
> _Products;
public DynaList<
Product
> Products
{
get
{
if (_Products == null)
_Products = new DynaList<
Product
>();
return _Products;
}
set
{
_Products = value;
}
}
private
void
DataGridProducts_KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.Key == Key.RightShift)
{
DataGridProducts.CommitEdit();
AddNewProduct();
DataGridProducts.SelectedItem = DataGridProducts.Items[Products.Count - 1];
}
}
protected
void
AddNewProduct()
{
Product tempProduct =
new
Product();
Products.Insert(Products.Count, tempProduct);
}