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

set the inserted row as selected

1 Answer 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Iwan van Ee
Top achievements
Rank 1
Iwan van Ee asked on 27 Mar 2012, 12:09 PM
I tried to set the new added row as the selected row, but have some strange effects.
In the grid I have set IsSynchronizedWithCurrentItem to true, because I want the arrow to follow the selected row (currentItem).
Also set the ShowInsertRow to true.

After the user has clicked on that row, filled in his information and presses the Enter key, I'd like to set this newly added row as the selected row with the Arrow (IsSynchronizedWithCurrentItem) also set to this row.

With AddingNewDataItem I create the new item with default values.

In the RowEditEnded I add this new object to the ObjectContext, save the changes in the context and do the following check:
if (e.Row is GridViewNewRow)
{
  ScrollIntoView(grdDataGrid, e.Row.Item);
}

Then I have the ScrollIntoView function:
private void ScrollIntoView(RadGridView grd, object itmSel)
{
  grd.SelectedItem = itmSel;
  grd.ScrollIntoViewAsync(grd.SelectedItem, r =>
  {
    var row = r as GridViewRow;
    if (row != null)
    {
      row.IsCurrent = true;
      row.IsSelected = true;
      row.Focus();
    }
    grd.CurrentItem = itmSel;
    grd.CurrentCellInfo = new GridViewCellInfo(grd.SelectedItem, grd.Columns[0]);
  });
 
}


It looks like it's working, but I still have the previous selected row ALSO having the Arrow mark. When I select a different row the newly selected row get the arrow mark, but my new added row keeps also having the arrow mark. 
I need to select the new added row then select a different row to have it all working. 

What's wrong here? Using WPF Q1 2012.





1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Mar 2012, 08:47 AM
Hi,

 I have created a test project based on your code snippets. Still I was not able to reproduce the case when both the rows (the old selected and the newly added and selected row) have the current arrow.

Please find the attached project and let me know how I can get the behaviour that you describe. 

Regards,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Iwan van Ee
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or