如何设置副本数等于DataGridView中的数量

时间:2019-04-09 08:31:29

标签: c# datagridview reportviewer

我有一个与excel表格连接的Datagridview。我的Excel工作表是一张很好的收据,其中包含项目的数量。现在我想打印标签的数量一样多。例如,如果我有10件T恤,我想打印数量为1的10个标签。

我已经尝试了以下代码。

        private void btnSingle_Click(object sender, EventArgs e)
    {
        BindingList<LableClass> GoodReceipt= new BindingList<LableClass>();
        GoodReceipt.Add(new LableClass()
    {
       Charge = dataGridView1.SelectedCells[0].Value.ToString(),
       ItemNr= dataGridView1.SelectedCells[1].Value.ToString(),
       Description= dataGridView1.SelectedCells[2].Value.ToString(),
       Quantity= float.Parse(dataGridView1.SelectedCells[8].Value.ToString())
    });
        LableClassBindingSource.DataSource = GoodReceipt;

        PrinterSettings prtSetting = new PrinterSettings();


        foreach (PaperSize item in prtSetting.PaperSizes)
        {
            if (item.PaperName == "62mm x 29mm")
                prtSetting.DefaultPageSettings.PaperSize = item;
        }
        PageSettings ps = new PageSettings(prtSetting);
        ps.Landscape = false;

        ps.Margins.Top = 8;
        ps.Margins.Bottom = 0;
        ps.Margins.Left = 6;
        ps.Margins.Right = 0;


        PrintDocument prtDoc = new PrintDocument();

        prtDoc.PrinterSettings = prtSetting;

        prtSetting.Copies = 5;
        prtSetting.FromPage = 1;
        prtSetting.ToPage = 5;
        reportViewer1.SetPageSettings(ps);
        prtDoc.Print();

        reportViewer1.RefreshReport();

    }

我尝试打印5个标签进行测试,但是不知何故所有标签都是空的。对不起,英语不好。

0 个答案:

没有答案