I want to set focus to the default 'add-row' in an UltraGrid and put that row in edit mode. How can I access this row? In the documentation this row is referred to as the template add-row and allows the user to add a new row by simply typing into it.
Thanks in advance.
Jay
Hi Jay,
You can access the template add row via the TemplateAddRow property on the rows collection. So for the root level rows, it would go something like this:
this.ultraGrid1.ActiveCell = this.ultraGrid1.Rows.TemplateAddRow.Cells[0]; this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
Bear in mind that you cannot set focus to any control inside events that fire before the form paints, like Form_Load. So this code won't work there. If you want to do this initially when your form is first displayed, you can probably do it by uing BeginInvoke to call a method, rather than calling the code directly.
Thanks Mike. Please can you explain how I would implement BeginInvoke functionality?
Thanks
You will need to check Microsof's documentation for details on BeginInvoke. But a very simple example might look like this:
private void Form1_Load(object sender, System.EventArgs e) { // Bind the grid
this.BeginInvoke(new MethodInvoker(this.SetFocusToTemplateAddRow)); } private void SetFocusToTemplateAddRow() { this.ultraGrid1.ActiveCell = this.ultraGrid1.Rows.TemplateAddRow.Cells[0]; this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode); }
Works perfectly. THANKS!!!!
Thanks for your help. I've not tried your solution yet but it looks good.