This sample demonstrates the synchronization between the Grid Grouping Control and the GridDataBound Control.
Both controls share the same data source and binding context. Changes in one control will automatically be reflected in the grid grouping control. When you categorize the date in the grid grouping control, you will also notice that the grouping engine automatically synchronizes and sorts the records according to their group category. New groups are created or removed on the fly while you enter data.
The following image shows both the grids reflecting the same values after making changes.
The following code creates a data set, and fills it with data from the ACC.csv file through the OLE data adapter.
private DataSet GetACCDataSet() { OleDbConnection conn = null; DataSet ds = null; try { string fileName = @"Data\ACC.csv"; for (int n = 0; n < 7; n++) { if (File.Exists(fileName)) { break; } fileName = @"..\" + fileName; } string dir = Path.GetDirectoryName(fileName); string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + ";Extended Properties=Text;"; conn = new OleDbConnection(connString); conn.Open(); string select = "SELECT * FROM ACC.csv"; OleDbDataAdapter adapt = new OleDbDataAdapter(select, conn); ds = new DataSet(); adapt.Fill(ds, "ACCStats"); conn.Close(); } catch(Exception ex) { if(conn != null && conn.State == ConnectionState.Open) { conn.Close(); MessageBox.Show(ex.ToString()); } return null; } return ds; }
Here is the code used to set the same data view for both the Grid data-bound grid control and the Grid Grouping control.
DataSet ds = GetACCDataSet(); DataView dv = ds.Tables["ACCStats"].DefaultView; this.gridGroupingControl1.TableDescriptor.AllowNew = false; this.gridGroupingControl1.DataSource = dv; //ds.Tables["ACCStats"]; this.gridDataBoundGrid1.DataSource = dv; this.gridDataBoundGrid1.UseListChangedEvent = true;