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

Add new row on key down.

3 Answers 190 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 07 Sep 2011, 07:16 PM
Hi,

Is it possible to add a new row on the keydown event and not lose focus in the cell the event was trapped in.  I know I can use gridView.BeginInsert(), but this causes focus to be lost from the cell that was being edited.  Specifically, we are trying to have an empty row, begin adding data to that row, while we are adding data to that row (only on the first keydown event of that row) we want a new (empty) row to appear and still have focus on the original row (cell) so we can continue adding data.

Also, on a related note, is adding an object to our ItemsSource bound collection the only way to have an empty last row in the GridView?

Thanks,

Mike

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 13 Sep 2011, 12:55 PM
Hi Michael,

As I understand from your post, you would like to have a row in edit mode. Then you press a key down and a new row is added at the end of the GridView.

 A possible approach in order to achieve this would be to subscribe for the KeyDown and RowEditEded events of the GridView and implement your logic there:

private GridViewRow rowInEditMode = null;
 
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void clubsGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (clubsGrid.RowInEditMode != null && rowInEditMode == null)
            {
                rowInEditMode = clubsGrid.RowInEditMode;
                (clubsGrid.ItemsSource as ObservableCollection<Club>).Add(new Club());
                //e.Handled = true;
            }
        }
 
        private void clubsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (rowInEditMode != null)
            {
                rowInEditMode = null;
            }
        }

If you would like the first 'key' to be not typed into the edited cell, then you should call e.Handled=true; inside the KeyDown event handler.

On your second question,  what you could check is the 'ShowInsertRow' of the GridView. You can have an always visible new row at the top of the GridView by setting the ShowInsertRow property of the RadGridView to True. Note it will be visible even when the CanUserInsertRows is set to False or the IsReadOnly property is set to True, however the user will still not be able to use it.

I hope that this is helpful.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 14 Sep 2011, 04:06 PM
Thanks, that is what we had started to do - looks like it will work but still needs tweaking on our end.  The ShowInsertRow is not the functionality we are looking for so we are going with  filling the data source with a blank object/row.  Is there any future plan to handle the NewItemPlaceholder of a CollectionView which auto-displays an empty row on the bottom of the grid?

Thanks,

Mike
0
Nedyalko Nikolov
Telerik team
answered on 19 Sep 2011, 03:21 PM
Hi Michael,

I've created a new feature request where you can vote (raise the priority) for this feature.
Our idea is to provide a possibility to set different position for the new item. 
Here is the public link.
Thank you for your feedback.

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Michael
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or