This thread provides C# code equivalents for this thread.Code:private void Form1_Load(object sender, EventArgs e) { this.bindingSource1.DataSource = this.GetChildTable(); this.dataGridView1.DataSource = this.bindingSource1; } private DataTable GetChildTable() { DataTable table = new DataTable(); table.Columns.Add("ChildID", typeof(int)); table.Columns.Add("ParentID", typeof(int)); table.Columns.Add("ChildName", typeof(string)); table.Rows.Add(1, 3, "Child 1"); table.Rows.Add(2, 2, "Child 2"); table.Rows.Add(3, 1, "Child 3"); return table; }Note that, when you add that code, you'll also have to select the form's Load event handler in the designer.Code:private void Form1_Load(object sender, EventArgs e) { this.bindingSource2.DataSource = this.GetParentTable(); this.Column1.DisplayMember = "ParentName"; this.Column1.ValueMember = "ParentID"; this.Column1.DataSource = this.bindingSource2; this.bindingSource1.DataSource = this.GetChildTable(); this.dataGridView1.DataSource = this.bindingSource1; } private DataTable GetParentTable() { DataTable table = new DataTable(); table.Columns.Add("ParentID", typeof(int)); table.Columns.Add("ParentName", typeof(string)); table.Rows.Add(1, "Parent 1"); table.Rows.Add(2, "Parent 2"); table.Rows.Add(3, "Parent 3"); return table; } private DataTable GetChildTable() { DataTable table = new DataTable(); table.Columns.Add("ChildID", typeof(int)); table.Columns.Add("ParentID", typeof(int)); table.Columns.Add("ChildName", typeof(string)); table.Rows.Add(1, 3, "Child 1"); table.Rows.Add(2, 2, "Child 2"); table.Rows.Add(3, 1, "Child 3"); return table; }




Reply With Quote