GridView -add new row

5 posts, 0 answers
  1. liza g
    liza g avatar
    24 posts
    Member since:
    Dec 2009

    Posted 20 May 2010 Link to this post

    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.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 May 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 14 Jul 2010 Link to this post

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



  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Jul 2010 Link to this post

    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
  6. Ahmet Özgür
    Ahmet Özgür avatar
    37 posts
    Member since:
    Jul 2009

    Posted 21 Jul 2010 Link to this post

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

Back to Top
UI for WPF is Visual Studio 2017 Ready