【发布时间】:2015-02-14 06:08:34
【问题描述】:
我遇到了一个问题,我在数据集中有一组数据表。我想在 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);
这些数据没有任何关系。它们只是一些计算的结果 如果不可能,我如何以用户友好的方式显示这些数据? 非常感谢
【问题讨论】:
-
先显示一些代码
-
如果表之间没有关系,则为所有表添加单独的数据网格。或者定义一个
DataTable并使用foreach循环,将所有dataTables添加到新的datatable中。试试forech (DataRow row in Table1.Rows) { newDataTable.Rows.Add(...)(会有点棘手)。仅当它不是大量数据时才这样做。如果是这样,请使用单独的dataGrids。 -
@DhavalR 谢谢。我的数据网格..有没有更好的解决方案向用户显示这些结果?
-
如果您真的想在单个
dataGrid中显示数据,您可以尝试第三方控制。其中之一是SourceGrid。