How to update the cell content on AddNewRecord in WinForms GridGroupingControl?
Update cell content on AddNewRecord
In order to
update a computed value in the WinForms
GridGroupingControl 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#
// 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
' 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 SubScreenshot:
New value is being added to the cell value of the record.

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

Samples:
Conclusion
I hope you
enjoyed learning about how to update the cell content on AddNewRecord in
WinForms GridGroupingControl.
You can refer
to our WinForms GridGroupingControl’s feature tour page to
know about its other groundbreaking feature representations. You can also
explore our WinForms GridGroupingControl documentation to
understand how to present and manipulate data.
For current
customers, you can check out our WinForms components from the License and
Downloads page. If you are new to Syncfusion, you can try our
30-day free trial to check out our WinForms
GridGroupingControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!