Articles in this section
Category / Section

How to update the CRUD operations in database in WinForms GridGroupingControl?

2 mins read

CRUD operation in database

By default, GridGroupingControl does not have direct support to update the changes to the database. To update the changes to database, manipulate the data in the SourceListRecordChanged event based on Action property value.

C#

//Event Subscription
this.gridGroupingControl1.SourceListRecordChanged += gridGroupingControl1_SourceListRecordChanged;
 
//Event Customization
void gridGroupingControl1_SourceListRecordChanged(object sender, Syncfusion.Grouping.RecordChangedEventArgs e)
{
    //To update database for addition.
    if (e.Action == Syncfusion.Grouping.RecordChangedType.Added)
    {
        String column1Value = e.Record.GetValue("id").ToString();
        string column2Value = e.Record.GetValue("desc").ToString();
        string txtSQLQuery = "insert into  mains ([id],[desc]) values ('" + column1Value + "','" + column2Value + "')";
        ExecuteQuery(txtSQLQuery);
    }
    //Update db for Deletion.
    if (e.Action == Syncfusion.Grouping.RecordChangedType.Removed)
    {
        String value = e.Record.GetValue("id").ToString();
        string txtSQLQuery = "delete from  mains where id =" + value;
 
        ExecuteQuery(txtSQLQuery);
    }
    //Update the db when modify the cell value.
    if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord)
        return;
    String columnName = e.Record.GetValue("id").ToString();
    Object val = e.Record.GetValue(columnName);
    object unique = e.Record.GetValue("id");
    if (val == null || unique == null)
        return;
    string value1 = val.ToString();
 
    string txtSQLQuery1 = "update  mains set  " + columnName + " =\"" + value1 + "\" where id =" + unique.ToString();
    ExecuteQuery(txtSQLQuery1);
}

 

VB

'Event Subscription
AddHandler Me.gridGroupingControl1.SourceListRecordChanged, AddressOf gridGroupingControl1_SourceListRecordChanged
 
'Event Customization
Private Sub gridGroupingControl1_SourceListRecordChanged(ByVal sender As Object, ByVal e As Syncfusion.Grouping.RecordChangedEventArgs)
    'Update db when adding records.
    If e.Action = Syncfusion.Grouping.RecordChangedType.Added Then
        Dim column1Value As String = e.Record.GetValue("id").ToString()
        Dim column2Value As String = e.Record.GetValue("desc").ToString()
        ExecuteQuery("insert into  mains ([id],[desc]) values ('" & column1Value & "','" & column2Value & "')")
    End If
    'Update db for Deletion.
    If e.Action = Syncfusion.Grouping.RecordChangedType.Removed Then
        Dim value1 As String = e.Record.GetValue("id").ToString()
        Dim txtSQLQuery1 As String = "delete from  mains where id =" & value1
 
        ExecuteQuery(txtSQLQuery1)
    End If
    'Update the db when modify the cell value.
    If e.Record.Kind = Syncfusion.Grouping.DisplayElementKind.AddNewRecord Then
        Return
    End If
    Dim columnName As String = e.Record.GetValue("id").ToString()
    Dim val As Object = e.Record.GetValue(columnName)
    Dim unique As Object = e.Record.GetValue("id")
    If val Is Nothing OrElse unique Is Nothing Then
        Return
    End If
    Dim value As String = val.ToString()
 
    Dim txtSQLQuery As String = "update  mains set  " & columnName & " =""" & value & """ where id =" & unique.ToString()
    ExecuteQuery(txtSQLQuery)
End Sub

 

Samples:

C#: To update CRUD operations_CS

VB: To update CRUD operations_VB

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied