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

[Solved] DataGrid_DataLoaded fires too early

3 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
tsvika
Top achievements
Rank 1
tsvika asked on 26 Dec 2010, 09:01 AM
Hi

I have a grid that is bounded to a ViewModel Collection<Entity>.
When I add a row to the collection the grid is refreshed and the new row becomes visible.

I need to put a cell in the new row in edit mode automatically, by setting the :
cell.IsInEditMode = true;
The problem is that   "DataLoaded " fires before the view is refreshed, so my code cannot find the new row, and fails:

private void linesDataGrid_DataLoaded(object sender, EventArgs e)
        {
            if (_viewModel.IsPutEditModeOnNewRowEnabled)
            {
                RadGridView linesDataGrid = (RadGridView)CustomVisualTreeHelper.SearchFrameworkElement(_receiptDetails, "linesDataGrid");
                GridViewCell cell = TelerikGridHelper.GetCellByIndexes(linesDataGrid, _viewModel.Lines.Count, 2);
                cell.IsInEditMode = true;
                _viewModel.IsPutEditModeOnNewRowEnabled = false ;
            }
        }

I also tried _RowLoaded , this had the same result.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Dec 2010, 08:26 AM
Hello tsvika,

In order to provide you with a proper solution, I would need a bit more details about the way you add a new item. Do you add a new item on a button click or you use the Insert key for it ? 

Kind regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
tsvika
Top achievements
Rank 1
answered on 27 Dec 2010, 04:31 PM
Hi

I don't use the code behind(because of MVVM) or the add button in the view (Because I want UI outside the gridview to perform the adding command).

to add the new row : I add it to the ViewModel>Collection that is bounded to the ItemSource of the GridView, and than raise OnPropertyChanged on it.

Can I still set a cell in the new row added  to be in "Edit Mode" after the data is refreshed (I know that the added row will become the last one) ?
0
Maya
Telerik team
answered on 27 Dec 2010, 04:59 PM
Hi tsvika,

Unfortunately, you cannot get the desired result by codelessly adding new item in the collection and still put this item into edit mode. What you can do is to handle the AddingNewDataItem event of the grid and insert the new item.

Greetings,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
tsvika
Top achievements
Rank 1
Answers by
Maya
Telerik team
tsvika
Top achievements
Rank 1
Share this question
or