if (routes.Length == 2)
            {
                frm.dgvInfo1[1, 0].Value = lstTemp[0].Re;
                frm.dgvInfo1[2, 0].Value = lstTemp[0].MaxWeight;
                frm.dgvInfo1[3, 0].Value = lstTemp[0].MaxVolume;
                frm.dgvInfo1[4, 1].Value = lstTemp[0].QuotaWeight + "/" + lstTemp[0].QuotaVolume + "/" + lstTemp[0].QuotaULD;
            }
            if (routes.Length == 3)
            {
                frm.dgvInfo1[1, 0].Value = lstTemp[0].Re;
                frm.dgvInfo1[2, 0].Value = lstTemp[0].MaxWeight;
                frm.dgvInfo1[3, 0].Value = lstTemp[0].MaxVolume;                frm.dgvInfo1[1, 2].Value = lstTemp[2].Re;
                frm.dgvInfo1[2, 2].Value = lstTemp[2].MaxWeight;
                frm.dgvInfo1[3, 2].Value = lstTemp[2].MaxVolume;
                frm.dgvInfo1[4, 1].Value = lstTemp[0].QuotaWeight + "/" + lstTemp[0].QuotaVolume + "/" + lstTemp[0].QuotaULD;
                frm.dgvInfo1[5, 1].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                               
                frm.dgvInfo1[4, 3].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                frm.dgvInfo1[5, 3].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
            }            if (routes.Length == 4)
            {
                frm.dgvInfo1[1, 0].Value = lstTemp[0].Re;
                frm.dgvInfo1[2, 0].Value = lstTemp[0].MaxWeight;
                frm.dgvInfo1[3, 0].Value = lstTemp[0].MaxVolume;                frm.dgvInfo1[1, 2].Value = lstTemp[3].Re;
                frm.dgvInfo1[2, 2].Value = lstTemp[3].MaxWeight;
                frm.dgvInfo1[3, 2].Value = lstTemp[3].MaxVolume;                frm.dgvInfo1[1, 4].Value = lstTemp[5].Re;
                frm.dgvInfo1[2, 4].Value = lstTemp[5].MaxWeight;
                frm.dgvInfo1[3, 4].Value = lstTemp[5].MaxVolume;
                frm.dgvInfo1[4, 1].Value = lstTemp[0].QuotaWeight + "/" + lstTemp[0].QuotaVolume + "/" + lstTemp[0].QuotaULD;
                frm.dgvInfo1[5, 1].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                frm.dgvInfo1[6, 1].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;                frm.dgvInfo1[4, 3].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                frm.dgvInfo1[5, 3].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                frm.dgvInfo1[6, 3].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                frm.dgvInfo1[7, 3].Value = lstTemp[4].QuotaWeight + "/" + lstTemp[4].QuotaVolume + "/" + lstTemp[4].QuotaULD;                frm.dgvInfo1[4, 5].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                frm.dgvInfo1[6, 5].Value = lstTemp[4].QuotaWeight + "/" + lstTemp[4].QuotaVolume + "/" + lstTemp[4].QuotaULD;
                frm.dgvInfo1[7, 5].Value = lstTemp[5].QuotaWeight + "/" + lstTemp[5].QuotaVolume + "/" + lstTemp[5].QuotaULD;
            }            if (routes.Length == 5)
            {
                frm.dgvInfo1[1, 0].Value = lstTemp[0].Re;
                frm.dgvInfo1[2, 0].Value = lstTemp[0].MaxWeight;
                frm.dgvInfo1[3, 0].Value = lstTemp[0].MaxVolume;                frm.dgvInfo1[1, 2].Value = lstTemp[4].Re;
                frm.dgvInfo1[2, 2].Value = lstTemp[4].MaxWeight;
                frm.dgvInfo1[3, 2].Value = lstTemp[4].MaxVolume;                frm.dgvInfo1[1, 4].Value = lstTemp[7].Re;
                frm.dgvInfo1[2, 4].Value = lstTemp[7].MaxWeight;
                frm.dgvInfo1[3, 4].Value = lstTemp[7].MaxVolume;                frm.dgvInfo1[1, 6].Value = lstTemp[9].Re;
                frm.dgvInfo1[2, 6].Value = lstTemp[9].MaxWeight;
                frm.dgvInfo1[3, 6].Value = lstTemp[9].MaxVolume;
                frm.dgvInfo1[4, 1].Value = lstTemp[0].QuotaWeight + "/" + lstTemp[0].QuotaVolume + "/" + lstTemp[0].QuotaULD;
                frm.dgvInfo1[5, 1].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                frm.dgvInfo1[6, 1].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                frm.dgvInfo1[7, 1].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;                frm.dgvInfo1[4, 3].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                frm.dgvInfo1[5, 3].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                frm.dgvInfo1[6, 3].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                frm.dgvInfo1[7, 3].Value = lstTemp[4].QuotaWeight + "/" + lstTemp[4].QuotaVolume + "/" + lstTemp[4].QuotaULD;
                frm.dgvInfo1[8, 3].Value = lstTemp[5].QuotaWeight + "/" + lstTemp[5].QuotaVolume + "/" + lstTemp[5].QuotaULD;
                frm.dgvInfo1[9, 3].Value = lstTemp[6].QuotaWeight + "/" + lstTemp[6].QuotaVolume + "/" + lstTemp[6].QuotaULD;                frm.dgvInfo1[4, 5].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                frm.dgvInfo1[5, 5].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                frm.dgvInfo1[6, 5].Value = lstTemp[5].QuotaWeight + "/" + lstTemp[5].QuotaVolume + "/" + lstTemp[5].QuotaULD;
                frm.dgvInfo1[7, 5].Value = lstTemp[6].QuotaWeight + "/" + lstTemp[6].QuotaVolume + "/" + lstTemp[6].QuotaULD;
                frm.dgvInfo1[8, 5].Value = lstTemp[7].QuotaWeight + "/" + lstTemp[7].QuotaVolume + "/" + lstTemp[7].QuotaULD;
                frm.dgvInfo1[9, 5].Value = lstTemp[8].QuotaWeight + "/" + lstTemp[8].QuotaVolume + "/" + lstTemp[8].QuotaULD;                frm.dgvInfo1[4, 7].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                frm.dgvInfo1[5, 7].Value = lstTemp[6].QuotaWeight + "/" + lstTemp[6].QuotaVolume + "/" + lstTemp[6].QuotaULD;
                frm.dgvInfo1[6, 7].Value = lstTemp[8].QuotaWeight + "/" + lstTemp[8].QuotaVolume + "/" + lstTemp[8].QuotaULD;
                frm.dgvInfo1[7, 7].Value = lstTemp[9].QuotaWeight + "/" + lstTemp[9].QuotaVolume + "/" + lstTemp[9].QuotaULD;
            }
求 用 循环 如何实现  要C#代码

解决方案 »

  1.   

    简化一下。哈  if (routes.Length >= 2)
                {
                    frm.dgvInfo1[1, 0].Value = lstTemp[0].Re;
                    frm.dgvInfo1[2, 0].Value = lstTemp[0].MaxWeight;
                    frm.dgvInfo1[3, 0].Value = lstTemp[0].MaxVolume;
                    frm.dgvInfo1[4, 1].Value = lstTemp[0].QuotaWeight + "/" + lstTemp[0].QuotaVolume + "/" + lstTemp[0].QuotaULD;
                }
                if (routes.Length >= 3)
                {
                    frm.dgvInfo1[1, 2].Value = lstTemp[2].Re;
                    frm.dgvInfo1[2, 2].Value = lstTemp[2].MaxWeight;
                    frm.dgvInfo1[3, 2].Value = lstTemp[2].MaxVolume;
                    frm.dgvInfo1[5, 1].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                    frm.dgvInfo1[4, 3].Value = lstTemp[1].QuotaWeight + "/" + lstTemp[1].QuotaVolume + "/" + lstTemp[1].QuotaULD;
                    frm.dgvInfo1[5, 3].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                }            if (routes.Length >= 4)
                {
                    frm.dgvInfo1[1, 4].Value = lstTemp[5].Re;
                    frm.dgvInfo1[2, 4].Value = lstTemp[5].MaxWeight;
                    frm.dgvInfo1[3, 4].Value = lstTemp[5].MaxVolume;
                    frm.dgvInfo1[6, 1].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                    frm.dgvInfo1[6, 3].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                    frm.dgvInfo1[7, 3].Value = lstTemp[4].QuotaWeight + "/" + lstTemp[4].QuotaVolume + "/" + lstTemp[4].QuotaULD;
                    frm.dgvInfo1[4, 5].Value = lstTemp[2].QuotaWeight + "/" + lstTemp[2].QuotaVolume + "/" + lstTemp[2].QuotaULD;
                    frm.dgvInfo1[6, 5].Value = lstTemp[4].QuotaWeight + "/" + lstTemp[4].QuotaVolume + "/" + lstTemp[4].QuotaULD;
                    frm.dgvInfo1[7, 5].Value = lstTemp[5].QuotaWeight + "/" + lstTemp[5].QuotaVolume + "/" + lstTemp[5].QuotaULD;
                }            if (routes.Length >== 5)
                {         
                    frm.dgvInfo1[1, 6].Value = lstTemp[9].Re;
                    frm.dgvInfo1[2, 6].Value = lstTemp[9].MaxWeight;
                    frm.dgvInfo1[3, 6].Value = lstTemp[9].MaxVolume;
                    frm.dgvInfo1[7, 1].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                    frm.dgvInfo1[8, 3].Value = lstTemp[5].QuotaWeight + "/" + lstTemp[5].QuotaVolume + "/" + lstTemp[5].QuotaULD;
                    frm.dgvInfo1[9, 3].Value = lstTemp[6].QuotaWeight + "/" + lstTemp[6].QuotaVolume + "/" + lstTemp[6].QuotaULD;
                    frm.dgvInfo1[5, 5].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                    frm.dgvInfo1[8, 5].Value = lstTemp[7].QuotaWeight + "/" + lstTemp[7].QuotaVolume + "/" + lstTemp[7].QuotaULD;
                    frm.dgvInfo1[9, 5].Value = lstTemp[8].QuotaWeight + "/" + lstTemp[8].QuotaVolume + "/" + lstTemp[8].QuotaULD;
                    frm.dgvInfo1[4, 7].Value = lstTemp[3].QuotaWeight + "/" + lstTemp[3].QuotaVolume + "/" + lstTemp[3].QuotaULD;
                    frm.dgvInfo1[5, 7].Value = lstTemp[6].QuotaWeight + "/" + lstTemp[6].QuotaVolume + "/" + lstTemp[6].QuotaULD;
                    frm.dgvInfo1[6, 7].Value = lstTemp[8].QuotaWeight + "/" + lstTemp[8].QuotaVolume + "/" + lstTemp[8].QuotaULD;
                    frm.dgvInfo1[7, 7].Value = lstTemp[9].QuotaWeight + "/" + lstTemp[9].QuotaVolume + "/" + lstTemp[9].QuotaULD;
                }