7 Answers, 1 is accepted
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.
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.
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
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.
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
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.
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