2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Update cell content on AddNewRecordIn order to update a computed value in the WinForms Grid Control 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. 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 Grid Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Control documentation to understand how to present and manipulate data. For current customers, you can check out our WinForms 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 Grid Control 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!
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.