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
475
Add New Record feature behaviour
posted

I am using the Add New Record feature in my application via...

AddNewRecordLocation="OnTopFixed" AllowAddNew="True"

However, for a user the behaviour is not intuitive.  If it is the 1st row then the user starts typing in the AddNewRecord template row.  In order for them to commit the row they have to press the Enter key.  How are they supposed to know that ?

Whereas if you consider Microsoft Access table editing.  They display an AddNewRecord template at the bottom of the table data.  The moment you type in any cell then that becomes a live data row and a new AddNewRecord template appears below this.  No need for a user to know about hitting the Enter key.

How can I replicate this behaviour using the XamDataGrid ?

  • 4475
    posted

    Hello,

     

    I am just checking your progress on the issue.

     

    If you require any further assistance please do not hesitate to ask.

     

    Sincerely,

    Ekaterina

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

     

  • 4475
    posted

    Hello,


    I have been investigating into the issue that you are having and I do understand your concerns. In order to achieve similar behavior to the MS Access tables, you can force the record to be added to the grid by using ExecuteCommand method with DataPresenterCommands.EndEditModeAndCommitRecord argument. After that you can put the desired cell in edit mode by using ExecuteCommand again but this time with DataPresenterCommands.StartEditMode
     Argument. Notice that this command will make the current active cell in edit mode, so first make this cell the active one.

    The last thing you should consider, is the position of the cursor and the selection of the text in the selected editor, because the text in the cell will become selected as soon as you execute the abovementioned actions, so it is highly likely that the user will accidently override the selected text. To deal with that you can again use the fact that the needed cell is the active cell of the grid and access it via the corresponding CellValuePresenter. For example you can unselect the selected text in your XamTextEditor placed in the current active cell using that statement:
    (CellValuePresenter.FromCell(xamDataGrid1.ActiveCell).Editor as XamTextEditor).SelectionLength = 0;

    The above described code should be placed in the grids RecordAdded event handler. Here is a corresponding sample code:

    private void xamDataGrid1_RecordAdded(object sender, Infragistics.Windows.DataPresenter.Events.RecordAddedEventArgs e)
            {
                xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndCommitRecord);
                e.Record.Cells[0].IsActive = true;
                xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

                (CellValuePresenter.FromCell(xamDataGrid1.ActiveCell).Editor as XamTextEditor).SelectionLength = 0;
                (CellValuePresenter.FromCell(xamDataGrid1.ActiveCell).Editor as XamTextEditor).SelectionStart =
                     (CellValuePresenter.FromCell(xamDataGrid1.ActiveCell).Editor as XamTextEditor).Text.Length;
            }

    If you a have any further questions on that metter, please don’t hesitate to contact us.


    Sincerely,
    Ekaterina
    Developer Support Engineer
    Infragistics Inc.
    www.infragistics.com/support