Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
235
Enter edit-mode after adding new row
posted

I have a grid bound to a collection (ListCollectionView). I'm trying to add new item to the list by

    myList.Insert(0, viewModel);
    myList.MoveCurrentToPosition(0);

Grid has many columns and one is called "Name". It's a text field column with CellValuePresenter displaying text and background using some color.

Now, when I add new item to collection (when user presses "Add" button), I'd like to enter edit mode for Name field right away, so user can edit name without needing to double click on the fields first. The problem is that grid won't go into edit mode. I'm trying to enter edit mode using:

    dataGrid.ActiveRecord = dataGrid.Records[0]; // record is added on top
    dataGrid.ActiveCell = (dataGrid.Records[0] as DataRecord).Cells["Name"];
    CellValuePresenter cvp = CellValuePresenter.FromCell(dataGrid.ActiveCell);
    if (cvp != null)
        cvp.StartEditMode();

But, cvp returned is always null. I found out, that null is returned only for this newly added row, but works great if I use any cell from any other row. Is it because CellValuePresenter has not been created or initialized yet at this point?

Is there another way to start edit mode?

 

best regards

T