This sample shows you how to set up Windows Forms data binding between the current record of the Grid Grouping control and the external text boxes on a form.
Features:
Creates binding between the current grid record and the external text boxes.
Changing the current record will also change the bound text-box values.
This is how the sample looks.
Implementation:
Here is the code snippet:
// Code showing how the Data is bound to the GridGroupingControl. this.gridGroupingControl1.DataSource = this.dt.DefaultView;// Code showing how the Data is bound to the External TextBoxes. this.textBox1.DataBindings.Add("Text", this.dt.DefaultView, "Col1"); this.textBox2.DataBindings.Add("Text", this.dt.DefaultView,"Col2");// Optional Code. // At the time this ctor is running there is no Form.BindingContext. // We need to create a BindingContext and assign it manually, to avoid each control from creating it's own BindingContext. // If we delay accessing the GridGroupingControl records until Form1_Load is called, this work around will not be necessary. BindingContext bc = new BindingContext(); this.gridGroupingControl1.BindingContext = bc; this.textBox1.BindingContext = bc; this.BindingContext = bc;
The code that accesses the records (like SetCurrent, calling Records.Count, etc.) and the data-binding code should go into the Form1_Load to avoid flickering.