I can't find how to have a button or a blank line to add a new element to my List<> with my RadGridView.
I've the "CanUserInsertRows" checked, but nothing on the GUI permit me to add/delete an element.
We have to create ourself buttons to do this? Why have these properties then?
Thank you!
13 Answers, 1 is accepted
You need to set ShowInsertRow to true.
Greetings,Yavor Georgiev
the Telerik team

-Why when we are creating this row, it's not the "CurrentItem" or "CurrentSelection"?? I've to bind this new element, because only basic fields are displayed in the list and details are to fill in another panel.
-Is there a ShowDelete?
Thank you for your help
You can handle the CollectionChanged event of RadGridView.Items like so:
public
MainWindow()
{
InitializeComponent();
this
.clubsGrid.Items.CollectionChanged +=
new
System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_CollectionChanged);
}
void
Items_CollectionChanged(
object
sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if
(e.NewItems !=
null
&& e.NewItems.Count > 0)
{
this
.clubsGrid.SelectedItem =
this
.clubsGrid.CurrentItem = e.NewItems[0];
}
}
Greetings,
Yavor Georgiev
the Telerik team

Until you commit the row edit operation, the new (or modified) item does not end up in the GridView's items collection. Because of this, you cannot select or make current an object that is effectively not in RadGridView.Items.
What is your scenario? Perhaps we can find some alternative solution.
Yavor Georgiev
the Telerik team

in fact, there is two parallels panels, one is a list of all elements(currently it's for households) that have only a sublist of all fields available on the object, the other contains all fields in different textbox display. Textbox are bound to the currentItem of the list.
If we can have the element directly commited we can directly show an empty form on the other panel. It makes no sense for us to create a new "household" on the list and still have the other panel with the older infos.
The goal is to have all actions on the list(add-delete-select) directly on the list, and have directly other informations on the other panel(fill all informations).
We don't want to have buttons under the list because it's not integrated/pretty.
Try this:
private
bool
isAddingNewRow =
false
;
public
MainWindow()
{
InitializeComponent();
this
.clubsGrid.BeginningEdit += clubsGrid_BeginningEdit;
this
.clubsGrid.RowEditEnded += clubsGrid_RowEditEnded;
}
void
clubsGrid_RowEditEnded(
object
sender, GridViewRowEditEndedEventArgs e)
{
if
(
this
.isAddingNewRow)
{
this
.isAddingNewRow =
false
;
this
.clubsGrid.SelectedItems.Clear();
this
.clubsGrid.SelectedItems.Add(e.Row.Item);
this
.clubsGrid.BeginEdit();
}
}
void
clubsGrid_BeginningEdit(
object
sender, GridViewBeginningEditRoutedEventArgs e)
{
if
(e.Row
is
GridViewNewRow)
{
this
.isAddingNewRow =
true
;
this
.clubsGrid.CommitEdit();
e.Cancel =
true
;
}
}
Yavor Georgiev
the Telerik team

this
.clubsGrid.BeginningEdit += clubsGrid_BeginningEdit;
this
.clubsGrid.RowEditEnded += clubsGrid_RowEditEnded;
But it should get an event handler here, can you say me which one?
Those are the event handlers. I defined them in the code snippet in my previous post. If you're having difficulties with this, I'll be happy to prepare a sample solution for you.
Kind regards,Yavor Georgiev
the Telerik team

I was just saying it was missing something, normally it's
this
.clubsGrid.BeginningEdit += new EventHandlerTypeHere(clubsGrid_BeginningEdit);
And I'm missing the "EventHandlerTypeHere".
Thank you

Edit: forget it, I understood my error
I'm sorry for not seeing your previous response, there must have been a glitch in our forum system. The handler type for BeginningEdit is EventHandler<GridViewBeginningEditRoutedEventArgs>.
However, you can attach the methods handling the events just like I have. The compiler infers the handler type from the method's signature and does all the wiring for you.
Kind regards,Yavor Georgiev
the Telerik team

I have a grid view in my wpf window. Due to some restrictions, I am not supposed to do inline edit or add. So I want to do that on click of button. I need to put a Edit button on row level and one add button outside grid. On the click of these buttons, I want to display a wpf usercontrol/window that has all the fields of the data source. Would you please suggest which is better i.e to use a user control or a window?
Thanks in advance
Priya