Documentation not updated for IsAddNewRowIndex() for SfDataGrid.

Hello, 

I was trying to Implement cancellation of  adding new row if the data is invalid. I found the solution over the forum that depends on the helper method IsAddNewIndex(). Although the solution was provided for WPF but API Documentation suggests that it is also available for Winforms too. However I found that this method does not exist in the Syncfusion.Winforms.DataGrid.
 
But there exist a method named 'IsAddNewRowIndex()' which is doing something for which I wasted a lot of time. Although It was a no brainer but I was being too strict in following the documentation. I suggest you to get it updated.

Thank you.


2 Replies 1 reply marked as answer

SG shankul gupta June 15, 2021 08:05 AM UTC

Hello,

I also cannot able to find CurrentCellManager inside SelectionController. I am trying to use this snippet (given below) provided by you to a user who was trying to achieve the same thing as I am.


using Syncfusion.UI.Xaml.Grid.Helpers;
this.dataGrid.RowValidating += dataGrid_RowValidating;

void dataGrid_RowValidating(object sender, RowValidatingEventArgs args)

{

    if (this.dataGrid.IsAddNewIndex(args.RowIndex))

    {

        //Code for cancelling AddNew operation by validating the args.RowData

        if (this.dataGrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing)

            this.dataGrid.SelectionController.CurrentCellManager.EndEdit(true);

        var AddNewRowController = this.dataGrid.GetGridModel().AddNewRowController;

        AddNewRowController.CancelAddNew();

    }
}


But I found SelectionControllerBase object 'DataGrid' inside SelectionController which contains all the required methods that a suggested in the above snippet.

I want to know if using:

sfDataGrid1.SelectionController.DataGrid.CurrentCell.IsEditing

is same as using:

sfDataGrid1.SelectionController.CurrentCellManager.CurrentCell.isEditing


will they result in same output? Am I missing something?





MA Mohanram Anbukkarasu Syncfusion Team June 16, 2021 11:06 AM UTC

Hi shankul gupta, 

Thanks for contacting Syncfusion support.  

The document you have checked is for WPF SFDataGrid. CurrentCellManager is available in WPF SfDataGrid. However you can achieve the same in WinForms as shown in the following code example.  

Code example :  

this.sfDataGrid1.RowValidating += SfDataGrid1_RowValidating; 
 
private void SfDataGrid1_RowValidating(object sender, Syncfusion.WinForms.DataGrid.Events.RowValidatingEventArgs e) 
{ 
    if(this.sfDataGrid1.IsAddNewRowIndex(e.DataRow.RowIndex)) 
    { 
        if((e.DataRow.RowData as OrderInfo).OrderID == 0) 
        { 
            if (this.sfDataGrid1.CurrentCell.IsEditing) 
 
                this.sfDataGrid1.CurrentCell.EndEdit(true); 
 
            this.sfDataGrid1.View.CancelNew(); 
        } 
    } 
} 


Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon