我在我的项目中使用2 gridview
,我在一个网格上绑定了员工,我希望在第二个网格上显示每个员工的订单。我被困在过滤其他员工,当我点击显示订单按钮它显示我所有的订单,我怎么能指向正确的索引(员工选择)? 。
我的代码:
private void Form3_Load(object sender, EventArgs e)
{
using (NorthWindDataContext db = new NorthWindDataContext())
{
var query =
from d in db.Employees
select new
{
d.FirstName
};
dataGridView1.DataSource = query;
}
}
private void displayOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
using (NorthWindDataContext db = new NorthWindDataContext())
{
var query =
from o in db.Orders
select new
{
o.ShipName <----problem here :(
};
dataGridView2.DataSource = query;
}
}
请帮忙
由于
答案 0 :(得分:2)
你需要写一些类似的东西:
private void displayOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
using (NorthWindDataContext db = new NorthWindDataContext())
{
var query =
from o in db.Orders.
Where(item => item.ID == dataGridView1.SelectedValue)
select new
{
o.ShipName <----problem here :(
};
dataGridView2.DataSource = query;
}
}