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

Adding New row

7 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Naveen T
Top achievements
Rank 1
Naveen T asked on 17 Mar 2010, 03:34 PM
Hi,

I am adding New Row to QueryableCollectionView at runtime, its adding at end of the last row( rad grid),but i need to add new row to the First page-first row.


Regards,
Nav

7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 19 Mar 2010, 10:20 AM
Hi nav kum,

You have to insert the new item at index zero in the underlying collection, i.e. the collection that you have passed to the constructor of QueryableCollectionView. You can do it like this:

using System.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Telerik.Windows.Controls.GridView;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System;
 
namespace TicketID_291840_ColumnIsEnabled
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        ObservableCollection<Club> clubs = Club.GetClubs();
         
        public Window1()
        {
            InitializeComponent();
 
            var qcv = new QueryableCollectionView(this.clubs);
            this.clubsGrid.ItemsSource = qcv;
 
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.clubs.Insert(0, new Club("NewClub", DateTime.Now, 50000));
        }
    }
}

I have attached a sample project. I hope this helps.

Best wishes,
Ross
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
Jonx
Top achievements
Rank 2
answered on 27 Apr 2011, 04:32 AM
Hello Ross,
I have the same problem.
I'm using RIA Services.
And I insert my row with the "Insert new row" feature.
Once I press return, the row moves from the first row to the last one...
I would like the inserted rows be added on top of the grid and get their correct place only once I submitted the changes.
I asking this because I have more rows in my grid the visible on the screen.
That means that when I insert a row, once I press return, it looks like the rows disapears when it is moved to the end...
How can I change the way the grid inserts the new rows?
Thanks a lot in advance,
John.
0
Milan
Telerik team
answered on 27 Apr 2011, 08:36 AM
Hello John,

You can always set ShowInsertRow to true and have a pinned row shown at the top of the grid. That way you will not have to worry about item positioning. 


Greetings,
Milan
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
Jonx
Top achievements
Rank 2
answered on 27 Apr 2011, 12:23 PM
Hello Milan,
That is what I have. I use the Insert Row at the top to insert my new rows.
The problem I have is that once inserted (press return), the rows are added at the end of the collections when I want them to be inserted at the beginning. Also note that I'm talking about what I want before having submitted my changes. After that, I understand that the rows are sorted...
Do you see what I mean? Sorry for the bad explanation...
John.
0
Milan
Telerik team
answered on 28 Apr 2011, 11:48 AM
Hi John,

I afraid that new items are automatically added at the end of the source collection. RadGridView does not influence this mechanism in any way - i.e, this is not caused by RadGridView. Once way to deal with this is to have some custom field which will be used for sorting. Based on that field the new items will be placed on top of the grid. 

For example, this could be an integer field which has value of 1 for all old items and value of 0 for all new items. Once you add a SortDescriptor for this custom field the data will be sorted accordingly. 


Greetings,
Milan
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
Jonx
Top achievements
Rank 2
answered on 28 Apr 2011, 11:58 AM
Will this work even before I do submit the changes?

Maybe another solution would be to scroll the inserted row into view...
Can this be done? Would you mind showing how to do?
To scroll the newly inserted row into view...

Thank you for your help,
John.
0
Milan
Telerik team
answered on 03 May 2011, 03:25 PM
Hi John,

There should be no problem to do this. You can try the following:

public MainPage()
{
    InitializeComponent();
  
    this.playersGrid.RowEditEnded += new EventHandler<GridViewRowEditEndedEventArgs>(playersGrid_RowEditEnded);
}
  
void playersGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
    if (e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert)
        this.playersGrid.ScrollIntoViewAsync(e.EditedItem, null);
}


Kind regards,
Milan
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
Tags
GridView
Asked by
Naveen T
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Jonx
Top achievements
Rank 2
Milan
Telerik team
Share this question
or