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

Add a row?

13 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 13 Aug 2010, 10:27 AM
Hi!

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

Sort by
0
Yavor Georgiev
Telerik team
answered on 13 Aug 2010, 10:34 AM
Hello Julien,

 You need to set ShowInsertRow to true.

Greetings,
Yavor Georgiev
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
Julien
Top achievements
Rank 1
answered on 13 Aug 2010, 10:52 AM
Great, but:

-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
0
Yavor Georgiev
Telerik team
answered on 13 Aug 2010, 11:09 AM
Hi Julien,

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

We do not provide a built-in UI element for deletion, but you can always use keyboard keys to achieve the same effect: Insert, Delete, etc. If keyboard navigation is unsuitable for your needs, you can always place a button somewhere in your UI and set its command to RadGridViewCommands.Delete. You can see an example of this in our demos: All Controls > Data > GridView > Overview > Commands.

Greetings,
Yavor Georgiev
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
Julien
Top achievements
Rank 1
answered on 13 Aug 2010, 12:53 PM
I tried your solution, but the switch isn't made fast enough, it has to be done when we click on the "Click here to add...", with your solution it's made when we lost the focus of the first field we edit.
0
Yavor Georgiev
Telerik team
answered on 13 Aug 2010, 01:05 PM
Hello Julien,

 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.

Best wishes,
Yavor Georgiev
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
Julien
Top achievements
Rank 1
answered on 13 Aug 2010, 01:14 PM
Is there a way to commit directly when we create the element?

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.
0
Accepted
Yavor Georgiev
Telerik team
answered on 13 Aug 2010, 01:34 PM
Hi Julien,

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

Sincerely yours,
Yavor Georgiev
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
Julien
Top achievements
Rank 1
answered on 13 Aug 2010, 01:42 PM
you wrote:
    this.clubsGrid.BeginningEdit += clubsGrid_BeginningEdit;
    this.clubsGrid.RowEditEnded += clubsGrid_RowEditEnded;

But it should get an event  handler here, can you say me which one?
0
Yavor Georgiev
Telerik team
answered on 16 Aug 2010, 03:56 PM
Hi Julien,

 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
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
Julien
Top achievements
Rank 1
answered on 17 Aug 2010, 06:30 AM
Hum, I think there is a misunderstanding.

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
0
Julien
Top achievements
Rank 1
answered on 27 Aug 2010, 11:54 AM
I really need this response :(

Edit: forget it, I understood my error
0
Yavor Georgiev
Telerik team
answered on 27 Aug 2010, 12:06 PM
Hi Julien,

 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
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
Priyalakshmi
Top achievements
Rank 1
answered on 19 Oct 2012, 09:51 AM
Hello,

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
Tags
GridView
Asked by
Julien
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Julien
Top achievements
Rank 1
Priyalakshmi
Top achievements
Rank 1
Share this question
or