)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to update the cell content on AddNewRecord in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 15, 2016 |
Last Revised Date: February 12, 2020
Tags: addnewrow, update

Update cell content on AddNewRecord

In order to update a computed value in the AddNewRecord part which is being added, it can be done using the QueryCellStyleInfo event. In this article, the cell value of a record is being updated in another cell value depending upon the value specified.

C#

// Form()
// Hook the required event.
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
 
// Specify the criteria for updating.
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    double temp = 0.0;
    GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell;
    if (e.TableCellIdentity.TableCellType == GridTableCellType.AddNewRecordFieldCell && e.TableCellIdentity.Column.Name == "SampleData")
    {
        Element el = e.TableCellIdentity.DisplayElement;
        Record r = el.GetRecord();
        object ACol = r.GetValue("CategoryName");
                
        //The cellvalue to be computed and updated value.
        if (r != null && ACol != null && (double.TryParse(ACol.ToString(), out temp)))
        {
            object ob = (temp * 0.4).ToString();
            e.Style.CellValue = ob.ToString();
        }
    }
}

VB

' Form()
' Hook the required event.
AddHandler gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
 
' Specify the criteria for updating.
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
   Dim temp As Double = 0.0
   Dim cc As GridCurrentCell = Me.gridGroupingControl1.TableControl.CurrentCell
   If e.TableCellIdentity.TableCellType = GridTableCellType.AddNewRecordFieldCell AndAlso e.TableCellIdentity.Column.Name = "SampleData" Then
     Dim el As Element = e.TableCellIdentity.DisplayElement
     Dim r As Record = el.GetRecord()
     Dim ACol As Object = r.GetValue("CategoryName")
 
     'The cellvalue to be computed and updated value.
     If r IsNot Nothing AndAlso ACol IsNot Nothing AndAlso (Double.TryParse(ACol.ToString(), temp)) Then
       Dim ob As Object = (temp * 0.4).ToString()
       e.Style.CellValue = ob.ToString()
     End If
   End If
End Sub

Screenshot:

New value is being added in the cell value of the record.

Show the computed value in the column cell value

The computed value is updated in the cell value of the column “SampleData” simultaneously.

Show the updated value to AddNewRecord

Samples:

C#: UpdatingAddNewRecord_CS

VB: UpdatingAddNewRecord_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
Live Chat Icon