We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: GridGroupingControl
Tags: databinding

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

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile