Insert new row in grid grouping control after cell value validation

Good afternoon,
I have a question related to grid grouping control.
I use it to show data from my DB and I need to add a new row, inserting values directly from the grid.

I use TableControlCurrentCellValidating event for cell validating and gridCurrentRecordContextChange to insert row.

This is the code:

  private void gridCurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
        {
            //insert new row
            if (e.Record != null && e.Record.Kind == DisplayElementKind.AddNewRecord
            && e.Action == CurrentRecordAction.EndEditCalled)
            {
                GridAddNewRecord ganr = (GridAddNewRecord)e.Record;

                    //get row values
                    //insert in DB
                    //populate grid with new datasource
}
        }



I need to fire the event only if all cell's values are validated. Is there a way to do it?

Thank you

Best regards,
Federico


3 Replies

SN Sindhu Nagarajan Syncfusion Team June 13, 2018 01:16 PM UTC

Hi Federico, 
 
Thanks for using Syncfusion products. 
 
We have analyzed the code snippet that you provided. We are able to understand your scenario. According to GridGroupingControl architecture, CurrentRecordContextChange event will be triggered for the every action performed in the current cell (like BeginEditCalled, BeginEditCompleted etc.). If you want to restrict the insert operation for all the CurrentRecordActions for the invalid cells, you can check whether the cell has valid CellValue by using the IsValid property of GridCurrentCell. Please refer to the below code and sample, 
 
Code Example 
//Event Triggering 
this.gridGroupingControl1.CurrentRecordContextChange += GridGroupingControl1_CurrentRecordContextChange; 
 
//Event Customization 
private void GridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) 
{             
    if(this.gridGroupingControl1.TableControl.CurrentCell.IsValid) 
    { 
        // code snippet to insert row values 
    } 
} 
 
Sample Link: Sample 
 
Please let us know if you have any other queries. 
 
Regards, 
Sindhu TN 



FA Federico Ascoli June 14, 2018 07:39 AM UTC

Hi Sindhu,
thanks for your reply.

The method Table Control.Current Cell.IsValid works on current cell but I need to check that the entire Current Record is valid.

I can get it in this way:

Element el = this.gridAN.Table.GetInnerMostCurrentElement();
GridTable table = el.ParentTable as GridTable;
Record gridCurrentRecord = table.CurrentRecord;


Is there a way to iterate through it and check if all his cells are valid?

Thanks,
best regards

Federico



PM Piruthiviraj Malaimelraj Syncfusion Team June 15, 2018 05:19 AM UTC

Hi Federico,

 

Thanks for your update.

 

We could understand your scenario. You can get the all column values of a record by using Record.GetValue method. Please make use of the below code.

 

Code snippet:

Record currentRecord = e.TableControl.Table.CurrentRecord;

foreach(GridColumnDescriptor col in this.gridGroupingControl1.TableDescriptor.Columns)

{

    string cellValue =(string)currentRecord.GetValue(col.MappingName);

    //Your code

}

 

Please let us know if you have any queries,

 

Regards,

Piruthiviraj


Loader.
Up arrow icon