不用那么复杂,举NorthWind数据库的Customers和Orders表为例:SqlDataAdapter daa=new SqlDataAdapter("select * from Customers",this.sqlConnection1);
DataSet ds=new DataSet();
daa.Fill(ds,"customers");
daa.SelectCommand.CommandText="select * from Orders";
daa.Fill(ds,"orders");
ds.Relations.Add("customerID_relation",ds.Tables["customers"].Columns["CustomerID"],ds.Tables["orders"].Columns["CustomerID"]);
this.dataGrid1.DataSource=ds.Tables["customers"];
this.dataGrid1.DataMember="customerID_relation";
this.listBox1.DataSource=ds.Tables["customers"];
this.listBox1.DisplayMember="CompanyName";

解决方案 »

  1.   

    THANKS A LOT, 芝麻开门,I LOVE YOU!!!
      

  2.   

    If a pretty woman told me that,I would do everything for her
    开个玩笑 :)
      

  3.   

    我对Windows控件的数据绑定的本质真是狗屁都不了解。所以这个例子右边的DataGrid变为listBox时,我就又不知道该怎样实现了,也就是说点击左边listBox的某项,右边listBox里显示子表中某一字段的内容。help me again.
      

  4.   

    SqlDataAdapter daa=new SqlDataAdapter("select * from Customers",this.sqlConnection1);
    DataSet ds=new DataSet();
    daa.Fill(ds,"customers");
    daa.SelectCommand.CommandText="select * from Orders";
    daa.Fill(ds,"orders");
    ds.Relations.Add("customerID_relation",ds.Tables["customers"].Columns["CustomerID"],ds.Tables["orders"].Columns["CustomerID"]);
    this.listBox1.DataSource=ds.Tables["customers"];
    this.listBox1.DisplayMember="CompanyName";
    this.listBox2.DataSource=ds.Tables["Orders"];
    this.listBox2.DisplayMember="RequiredDate";
    ((DataTable)listBox2.DataSource).DefaultView.RowFilter="CustomerID='"+((DataRowView)this.BindingContext[listBox1.DataSource].Current)["CustomerID"].ToString()+"'";另外,在ListBox2的selectedIndexChanged事件中加入下面代码:
    ((DataTable)listBox2.DataSource).DefaultView.RowFilter="CustomerID='"+((DataRowView)this.BindingContext[listBox1.DataSource].Current)["CustomerID"].ToString()+"'";
      

  5.   

    listBox1.DataSource=ds;
    listBox1.DisplayMember = "customers.CompanyName";
    listBox2.DataSource = ds;
    listBox2.DisplayMember = "customers.customerID_relation.RequireDate";
    没测试,但想来应该可以.