private void InitializeControlsAndDataSource() { // Initialize the controls and set location, size and // other basic properties. this.dataGridView1 = new DataGridView(); this.bindingSource1 = new BindingSource(); this.button1 = new Button(); this.dataGridView2 = new DataGridView(); this.cachePositionCheckBox = new System.Windows.Forms.CheckBox(); this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Dock = DockStyle.Top; this.dataGridView1.Location = new Point(0, 20); this.dataGridView1.Size = new Size(292, 170); this.button1.Location = new System.Drawing.Point(18, 175); this.button1.Size = new System.Drawing.Size(125, 23); button1.Text = "Clear Parent Field"; this.button1.Click += new System.EventHandler(this.button1_Click); this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView2.Location = new System.Drawing.Point(0, 225); this.dataGridView2.Size = new System.Drawing.Size(309, 130); this.cachePositionCheckBox.AutoSize = true; this.cachePositionCheckBox.Checked = true; this.cachePositionCheckBox.Location = new System.Drawing.Point(150, 175); this.cachePositionCheckBox.Name = "radioButton1"; this.cachePositionCheckBox.Size = new System.Drawing.Size(151, 17); this.cachePositionCheckBox.Text = "Cache and restore position"; this.ClientSize = new System.Drawing.Size(325, 420); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.cachePositionCheckBox); this.Controls.Add(this.dataGridView2); this.Controls.Add(this.button1); // Initialize the data. set1 = InitializeDataSet(); // Set the data source to the DataSet. bindingSource1.DataSource = set1; //Set the DataMember to the Menu table. bindingSource1.DataMember = "Customers"; // Add the control data bindings. dataGridView1.DataSource = bindingSource1; // Set the data source and member for the second DataGridView. dataGridView2.DataSource = bindingSource1; dataGridView2.DataMember = "custOrders"; // Get the currency manager for the customer orders binding. CurrencyManager relatedCM = bindingSource1.GetRelatedCurrencyManager("custOrders"); // Set the position in the child table for demonstration purposes. relatedCM.Position = 3; // Handle the current changed event. This event occurs when // the current item is changed, but not when a field of the current // item is changed. bindingSource1.CurrentChanged += new EventHandler(bindingSource1_CurrentChanged); // Handle the two events for caching and resetting the position. relatedCM.ListChanged += new ListChangedEventHandler(relatedCM_ListChanged); relatedCM.PositionChanged += new EventHandler(relatedCM_PositionChanged); // Set cacheing to true in case current changed event // occured on set up. cacheChildPosition = true; }