After adding a new row to the RadGridView I wish to set focus and open for editing to the first column in the same way as I would do using BeginEdit() on a standard DataGrid?
I don't see an obvious way of doing so. Can someone explain how?
Thanks
Tom
7 Answers, 1 is accepted
RadGridView also has a method called BeginEdit but it is a little bit different from the one in DataGrid. Our method will open for editing the current cell, not the first one. In case you would like to always have the first cell in edit mode you can use this method:
private void MyBeginEdit() |
{ |
this.RadGridView1.BeginEdit(); |
((GridViewCell)this.RadGridView1.CurrentCell.ParentRow.Cells[0]).IsCurrent = true; |
this.RadGridView1.BeginEdit(); |
} |
the first call to BeginEdit is used to ensure that there is current cell.
Hope this helps.
Regards,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

Thanks. The BeginEdit() was not availble for me until I got the latest version of the RadGridView.
However when I use the suggested code you sent, it errors with a null object reference on the second line. I am trying to open for edit the first cell on a new row. So how do I select this so that the BeginEdit will done in the correct place?
I have tried the following ...
this
.datagridWOPriority.SelectedItem = e.NewObject;
this.datagridWOPriority.BeginEdit();
where e.NewObject is my added row.
It is a little bit unclear if you want to begin to insert a new item or to edit an already inserted new item.
In case you would like to insert a new row RadGridView exposes a method called BeginInsert that automatically shows the UI for inserting and focuses its first cell.
In case you would like to edit a random record you can try the modified version of MyBeginEdit:
private void MyBeginEdit(object item) |
{ |
var record = this.RadGridView1.FindRecord(item); |
this.RadGridView1.ItemsControl.BringDataItemIntoView(item); |
this.Dispatcher.BeginInvoke |
((Action)delegate |
{ |
if (!this.FindAndEdit(record)) |
this.Dispatcher.BeginInvoke(new Action(() => this.FindAndEdit(record))); |
} |
); |
} |
private bool FindAndEdit(Record record) |
{ |
var row = this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(record) as GridViewRow; |
if (row == null) |
return false; |
((GridViewCell)row.Cells[0]).IsCurrent = true; |
this.RadGridView1.BeginEdit(); |
return true; |
} |
The approach with setting the SelectedItem and then editing will not work because it will not change the current cell which is used when invoking BeginEdit.
Hope the new solution is working fine.
Greetings,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

2 further questions.
1) Is there a way of specifying that the new row created and opened with BeginInsert() will add the row at the bottom of the list rather than the top?
2) If I do two BeginInserts() without saving in between the first works fine but the second one causes the browser to error (with a null reference exception in debug). My new row event is ONLY calling BeginInsert() and I get the same error if I add the BeginInsert() to the newevent twice ... any suggestions as to what is going wrong here?
Unfortunately there is no property that will allow you to change the location of the new row but you can achieve that by providing custom style for RadGridView. I have prepared a sample solution that demonstrates how that can be achieved.
Could you provide more information about the exception? Which is element is reported as being null? Could you share the stacktrace?
All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

I implemented the code you suggested above. However when I use BringDataItemIntoView
It scrolls so that it appears my top most row in the grid has been removed - to compound this further the scroll bar does not work it is only when I use the keyboard to scroll up that I can see the rows are actually still in the grid.
Is this a known defect? Do you have any suggestions on how to work around?
I have modified the templates so you should be able to see vertical scrollbar and the BringDataItemIntoView method should work properly.
Do not hesitate to write if you encounter more problems.
Kind regards,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.