在winForms中的DataGrid视图中显示多个数据表



我遇到了一个问题,即数据集中有一组数据表。我想在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);

这些数据没有任何关系。它们只是一些计算的结果如果不可能,我如何以用户友好的方式显示这些数据?非常感谢

一个选项:在Linq中对这些表执行Join操作,将结果存储到数据表中;然后将这个新的数据表指定为网格的数据源。

这可能有助于连接linq中的数据表-linq连接两个数据表

最新更新