我有两个datasets
和两个datatables
。绑定并显示在两个datagrids
上:
//fill datatable
companiesDataTable = new DataTable("Companies");
scheduleDataTable = new DataTable("Schedule");
adapterCompanies.Fill(companiesDataTable);
adapterSchedule.Fill(scheduleDataTable);
//set dataset
myDataSet = new DataSet();
myDataSet.Tables.Add(companiesDataTable);
myDataSet.Tables.Add(scheduleDataTable);
//add relation
myDataSet.Relations.Add("FullSchedule",
myDataSet.Tables["Companies"].Columns["id"],
myDataSet.Tables["Schedule"].Columns["CompanyID"]);
//set binding sources
bsComp = new BindingSource(myDataSet, "Companies");
bsSched = new BindingSource(bsComp, "FullSchedule");
//fill datagrid
dataGridViewCompanies.DataSource = bsComp;
dataGridViewTimes.DataSource = bsSched;
如何过滤公司datagrid
而不与计划datagrid
失去联系?
我试过了,但关系似乎丢失了:
var view = myDataSet.Tables["Companies"].DefaultView;
view.RowFilter = filterString;
dataGridViewCompanies.DataSource = view;
答案 0 :(得分:0)
好吧,这简直令人尴尬:
bsComp.Filter = filterString;
dataGridViewCompanies.DataSource = bsComp;