Category / Section
How to reject the changes made in the WinForms GridGroupingControl?
1 min read
Reject the changes
By default, any change made to the GridGrouping control affects the underlying DataSource. The RejectChanges() method rejects the recent changes made to the DataSource without being saved. Ensure that the AcceptChanges() method is called after the DataSource is filled as the RejectChanges method rolls back all the changes made to the DataSource since the last call of the AcceptChanges method.
C#
private void btn_reject_Click(object sender, EventArgs e) { DataTable dt = this.gridGroupingControl1.DataSource as DataTable; //Rolls back all the changes made to the table since it was loaded or after the AcceptChanges() was called. dt.RejectChanges(); } private void btn_accept_Click(object sender, EventArgs e) { DataTable dt = this.gridGroupingControl1.DataSource as DataTable; //Commits all the changes made to the table. dt.AcceptChanges(); }
VB
Private Sub btn_reject_Click(ByVal sender As Object, ByVal e As EventArgs) Dim dt As DataTable = TryCast(Me.gridGroupingControl1.DataSource, DataTable) 'Rolls back all the changes made to the table since it was loaded or after the AcceptChanges() was called. dt.RejectChanges() End Sub Private Sub btn_accept_Click(ByVal sender As Object, ByVal e As EventArgs) Dim dt As DataTable = TryCast(Me.gridGroupingControl1.DataSource, DataTable) 'Commits all the changes made to the table. dt.AcceptChanges() End Sub
Samples: