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

Set Focus on cell, but it is lost while scolling

3 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 25 Mar 2011, 12:05 PM
Hello,
I am inserting a new row (or rather a new item in the itemssource) and then set the focus on a cell in this row, so that you can edit the cell. It works fine. I found the solution in another thread in the forum.

This code ist used:
private void SetFocusOnCellByValue(object cellValue)
{
    GridViewCell cell = this.GetCellByContent(cellValue);
    SetFocusOnCell(cell);
}
 
private GridViewCell GetCellByContent(object cellValue)
{
    return (from cell in this.RadGridViewRoles.ChildrenOfType<GridViewCell>()
            where cell.Value != null
            && cell.Value.ToString() == cellValue.ToString()
            select cell).FirstOrDefault();
}
 
private void SetFocusOnCell(GridViewCell cell)
{
   if (cell != null )
    {               
           cell.IsCurrent = true;
           cell.ParentRow.GridViewDataControl.CurrentColumn = cell.Column;
           cell.ParentRow.GridViewDataControl.CurrentItem = cell.DataContext;
           cell.IsInEditMode = true;
       
    }
}

SetFocusOnCellByValue is called here:
this.RadGridViewRoles.SelectedItem = null;
RoleType newRole = new RoleType();  // Items in the Itemssource are of own typ RoleType
newRole.displayName = "new role";
items.Insert(0, newRole);
this.RadGridViewRoles.SelectedItem = newRole;
this.RadGridViewRoles.ScrollIntoView(newRole);
SetFocusOnCellByValue("new role");

My problem occurs, when i add a new  role into the Itemssource and the column is sorted. The focus on the cell gets lost, when the new row occurs in a region, which is not visible before inserting an the GridView scrolls to the new row. You can see, that for a short moment, the cell ist selected an editable. But the focus gets lost then.

How can I solve this problem?

Thanks for help

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 31 Mar 2011, 12:19 PM
Hello Li,

Indeed when a cell is out f the viewport it can not gain the focus. Cells are virtualized , and actually only the cells visible exist and are rendered. 

The only workaround I can think of is to try bringing in view the row containing the cell . 
RadGridView exposes two methods that might be handy in this situation  - ScrolIntoView and ScrollIntoViewAsync. 

Hope that helps.
All the best,
Pavel Pavlov
the Telerik team
0
Li
Top achievements
Rank 1
answered on 01 Apr 2011, 08:39 AM
Hi,

I am already using scrollIntoView. It seems so, as if the cell gets focus for a short time an then lose it. The table is scrolled, the cell ist selected and editable and then, it is losing focus.

Do you have any other idea, to fix that problem?

Kind regards
Li
0
Li
Top achievements
Rank 1
answered on 01 Apr 2011, 10:34 AM
Hello,

now I am using ScrollIntoViewAsnc and it seems to work.
Thank you for help.

Best wishes,
Li
Tags
GridView
Asked by
Li
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Li
Top achievements
Rank 1
Share this question
or