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

GridView -add new row

4 Answers 407 Views
GridView
This is a migrated thread and some comments may be shown as answers.
liza g
Top achievements
Rank 1
liza g asked on 20 May 2010, 12:29 PM
hi,
i tried to add a new row in a editing gridview,
when I click on the InsertRow, it becomes an edit row
and I can edit.
but when I go out the row, it disappears from the gridview,
it remains in the ChangeSet object, and after SubmitChanges it added to the data.
I want to see the new row immediately after insertion, not just after the SubmitChanges function.
i'd love to see an example where it works
thanks.

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 25 May 2010, 02:05 PM
Hello liza g,

 
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.


Regards,
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.
0
David Brenchley
Top achievements
Rank 1
answered on 14 Jul 2010, 07:00 PM
I also have a similar issue to this.  When I would add a new row and tab out of it, the row would not display in the grid.  To resolve this, I had to rebind the CollectionViewSource I was using as the itemsource of the grid, for it to show up.  This seems to work, but the new row doesn't show any highlights, even though it is selected.

        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);
            }
        }



0
Maya
Telerik team
answered on 20 Jul 2010, 11:29 AM
Hello David Brenchley,

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.


  


Greetings,
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
0
Ahmet Özgür
Top achievements
Rank 1
answered on 21 Jul 2010, 01:47 PM
Maybe this can help,
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);
}

Tags
GridView
Asked by
liza g
Top achievements
Rank 1
Answers by
Maya
Telerik team
David Brenchley
Top achievements
Rank 1
Ahmet Özgür
Top achievements
Rank 1
Share this question
or