Diskuze: WinForms: Databind Relation na dvoch comboboxc
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
Zobrazeno 2 zpráv z 2.
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
..uvadzam funkcny kod:
private BindingSource bindingSource1 = new BindingSource();
private BindingSource bindingSource2 = new BindingSource();
InitializeComponent();
DataSet ds = new DataSet();
DataTable colors = new DataTable() { TableName = "colors" };
DataTable types = new DataTable() { TableName = "types" };
colors.Columns.Add("id", typeof(Int32));
colors.Columns.Add("color");
types.Columns.Add("id", typeof(Int32));
types.Columns.Add("id_color", typeof(Int32));
types.Columns.Add("type");
ds.Tables.Add(colors);
ds.Tables.Add(types);
ds.AcceptChanges();
colors.Rows.Add("1", "Red");
colors.Rows.Add("2", "Green");
types.Rows.Add("1", "1", "A");
types.Rows.Add("2", "1", "B");
types.Rows.Add("3", "2", "C");
types.Rows.Add("4", "2", "D");
ds.Relations.Add(new DataRelation("rel",
ds.Tables["colors"].Columns["id"],
ds.Tables["types"].Columns["id_color"]));
this.bindingSource1.DataSource = ds;
this.bindingSource1.DataMember = "colors";
this.bindingSource2.DataSource = this.bindingSource1;
this.bindingSource2.DataMember = "rel";
comboBox1.DataSource = this.bindingSource1;
comboBox1.DisplayMember = "color";
comboBox1.ValueMember = "id";
comboBox2.DataSource = this.bindingSource2;
comboBox2.DisplayMember = "type";
comboBox2.ValueMember = "id";
..vid. : http://www.vbforums.com/showthread.php?…)
R.
Zobrazeno 2 zpráv z 2.