我遇到了一个问题,我在数据集中有一组数据表。我想在DataGrid
视图中显示它们但它只能显示一个数据表。有没有办法显示更多的数据表网格视图中的数据表?我的意思是在表之间没有任何关系定义的多个数据表。
以下是我将数据添加到数据集的方法
DataSet ds = new DataSet();
DataTable RunoffEnergy = new DataTable();
RunoffEnergy.Columns.Add("RF");
RunoffEnergy.Columns.Add("LD");
RunoffEnergy.Columns.Add("DT");
RunoffEnergy.Columns.Add("K(DT)");
RunoffEnergy.Columns.Add("K(LD)");
RunoffEnergy.Columns.Add("KE");
RunoffEnergy.Rows.Add();
RunoffEnergy.Rows[0][0] = this.RF.ToString();
RunoffEnergy.Rows[0][1] = this.Ld.ToString();
RunoffEnergy.Rows[0][2] = this.Dt.ToString();
RunoffEnergy.Rows[0][3] = this.K_Dt.ToString();
RunoffEnergy.Rows[0][4] = this.K_Ld.ToString();
RunoffEnergy.Rows[0][5] = this.Ke.ToString();
//
DataTable EstimationOfRunoff = new DataTable();
EstimationOfRunoff.Columns.Add("Rc");
EstimationOfRunoff.Columns.Add("Qe");
EstimationOfRunoff.Columns.Add("Q");
EstimationOfRunoff.Rows.Add();
EstimationOfRunoff.Rows[0][0] = this.Rc.ToString();
EstimationOfRunoff.Rows[0][1] = this.Qe.ToString();
EstimationOfRunoff.Rows[0][2] = this.Q.ToString();
//
DataTable DetachmentOfSoilParticles = new DataTable();
DetachmentOfSoilParticles.Columns.Add("Fc", typeof(double));
DetachmentOfSoilParticles.Columns.Add("Fs");
DetachmentOfSoilParticles.Columns.Add("Fz");
DetachmentOfSoilParticles.Columns.Add("F", typeof(double));
DetachmentOfSoilParticles.Columns.Add("Hc");
DetachmentOfSoilParticles.Columns.Add("Hz");
DetachmentOfSoilParticles.Columns.Add("Hs", typeof(double));
DetachmentOfSoilParticles.Columns.Add("H");
DetachmentOfSoilParticles.Rows.Add();
DetachmentOfSoilParticles.Rows[0][0] = this.Fc;
DetachmentOfSoilParticles.Rows[0][1] = this.Fs.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.Fz.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.F.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.Hc.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.Hs.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.Hz.ToString();
DetachmentOfSoilParticles.Rows[0][2] = this.H.ToString();
//
DataTable ImidiateDepositionOfSoil = new DataTable();
ImidiateDepositionOfSoil.Columns.Add("Nfc", typeof(double));
ImidiateDepositionOfSoil.Columns.Add("Nfs");
ImidiateDepositionOfSoil.Columns.Add("Nfz");
ImidiateDepositionOfSoil.Columns.Add("DEPc", typeof(double));
ImidiateDepositionOfSoil.Columns.Add("DEPs");
ImidiateDepositionOfSoil.Columns.Add("DEPz");
ImidiateDepositionOfSoil.Rows.Add();
ImidiateDepositionOfSoil.Rows[0][0] = this.Nfc;
ImidiateDepositionOfSoil.Rows[0][1] = this.Nfs.ToString();
ImidiateDepositionOfSoil.Rows[0][2] = this.Nfz.ToString();
ImidiateDepositionOfSoil.Rows[0][2] = this.DEPc.ToString();
ImidiateDepositionOfSoil.Rows[0][2] = this.DEPs.ToString();
ImidiateDepositionOfSoil.Rows[0][2] = this.DEPz.ToString();
//
DataTable DeleveryOfDetachedParticles = new DataTable();
DeleveryOfDetachedParticles.Columns.Add("Gc", typeof(double));
DeleveryOfDetachedParticles.Columns.Add("Gs");
DeleveryOfDetachedParticles.Columns.Add("Gz");
DeleveryOfDetachedParticles.Columns.Add("G", typeof(double));
DeleveryOfDetachedParticles.Rows.Add();
DeleveryOfDetachedParticles.Rows[0][0] = this.Gc;
DeleveryOfDetachedParticles.Rows[0][1] = this.Gs.ToString();
DeleveryOfDetachedParticles.Rows[0][2] = this.Gz.ToString();
DeleveryOfDetachedParticles.Rows[0][2] = this.G.ToString();
//
DataTable TransportCapesity = new DataTable();
TransportCapesity.Columns.Add("Tc", typeof(double));
TransportCapesity.Columns.Add("Ts");
TransportCapesity.Columns.Add("Tz");
TransportCapesity.Columns.Add("T", typeof(double));
TransportCapesity.Rows.Add();
TransportCapesity.Rows[0][0] = this.Tc;
TransportCapesity.Rows[0][1] = this.Ts.ToString();
TransportCapesity.Rows[0][2] = this.Tz.ToString();
TransportCapesity.Rows[0][2] = this.T.ToString();
//
ds.Tables.Add(DeleveryOfDetachedParticles);
ds.Tables.Add(EstimationOfRunoff);
ds.Tables.Add(DetachmentOfSoilParticles);
ds.Tables.Add(ImidiateDepositionOfSoil);
// ds.Tables.Add(DeleveryOfDetachedParticles);
ds.Tables.Add(TransportCapesity);
这些数据没有任何关系。它们只是一些计算的结果 如果不可能,我怎样才能以用户友好的方式显示这些数据? 非常感谢你
答案 0 :(得分:1)
一个选项:在Linq中对这些表执行连接操作,将结果存储到数据表中;然后将此新数据表分配为网格的数据源。
这可能有助于在linq中加入数据表 - LINQ join two DataTables