如何在datagridview中打印所选复选框,以及如果没有选中打印全部 [英] How to print selected checkbox in datagridview and in case no checked print all

查看:73
本文介绍了如何在datagridview中打印所选复选框,以及如果没有选中打印全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


实际上我需要打印记录有复选框  checked
= true
 在datagridview内部

Actually I need to print records have checkbox checked = true inside datagridview


如果没有选中任何记录复选框  表示
= false
 选中print all

And if no any record checkbox checked meaning = false checked print all


我需要在按钮打印下执行此操作。

I need to do that under button print .


无需进入代码细节我只需要实现下面的伪代码:

No need to go inside code details I need only to implement only pseudo code below :


伪代码

if(any records checked checkbox = true)

    print checked only in datagridview

else

    print all in datagridview(in case no any checkbox checked inside grid)



我的当前代码打印全部:

my current code print all :

private void btnPrint_Click(object sender, EventArgs e)
{
    for (int i = 0; i < Grid.Rows.Count; i++)
    {
        if (string.IsNullOrEmpty(Convert.ToString(Grid.Rows[i].Cells["ItemCode"].Value))) return;
        Dictionary<string, string> Formulas = new Dictionary<string, string>();
        Formulas.Add("ImgFlds", BarcodePath);
        for (int x = 0; x < 4; x++)
        {
            string formula = "";
            int fieldVal = 0;

            if (x == 0)
            {
                formula = "lefttopcap";
                fieldVal = lefttopcap;
            }
            else if (x == 1)
            {
                formula = "righttopcap";
                fieldVal = righttopcap;
            }
            else if (x == 2)
            {
                formula = "leftbottomcap";
                fieldVal = leftbottomcap;
            }
            else if (x == 3)
            {
                formula = "rightbottomcap";
                fieldVal = rightbottomcap;
            }

            switch (fieldVal)
            {
                case 1:
                    break;
                case 2:
                    Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["CompanyName"].Value));
                    break;
                case 3:
                    Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["BranchName"].Value));
                    break;
                case 4:
                    Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["ItemLatName"].Value));
                    break;
                case 5:
                    Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["ItemAraName"].Value));
                    break;
                case 6:
                    Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["SelPrice1"].Value));
                    break;

                default:
                    break;
            }
        }

        string sql = "select * from Branches where 1=1 ";
        int z = !string.IsNullOrEmpty(Convert.ToString(Grid.Rows[i].Cells["ItemCount"].Value)) ? Convert.ToInt32(Convert.ToString(Grid.Rows[i].Cells["ItemCount"].Value)) : 1;

        Reporting.PrinterName = cmbPrinterType.Text; 
        Reporting.PrintType = PrintTypes.Print;
        CreateBarcode(Convert.ToString(Grid.Rows[i].Cells["code"].Value).Trim());
        picItem.Image.Save(BarcodePath);
        Reporting.ShowReport("BarcodePrinting.rpt", sql, Formulas, z);
    }
}








来检查数据gridview中的复选框如下:

to get checked checkbox in data gridview as following

bool isSelected = Convert.ToBoolean(Grid.Rows[i].Cells["SelectedPrint"].Value);
if (isSelected)
{
}






推荐答案

您好,

 只需遍历每个对象,如果check = true则打印对象。

 Just loop through each object and if check = true then print object.

目的是什么打印所有检查错误的对象?您可以

What is the purpose of print all objects that are check false? You could

对Checked事件处理程序进行编码,以将该对象保存到容器中,即

code the Checked event handler to save that object to container, i.e.

List<>或Stack<>等。 &NBSP;如果容器数!=零,则打印

List<>, or Stack<>, etc.  If the the container count != zero then print

这些对象作为对Grid.Row对象的引用。 我想你想

those object as a reference to Grid.Row objects.  I guess you want to

在同一个按钮事件中打印选定并打印全部?有许多

Print Selected and Print All in the same button event? There are many

实现您的请求的代码方法。大多数取决于应用

methods of code to implement your request. Most depend on the app

流量和您的偏好。

 

  BTW,您提供的代码可以使用一些改进。也许

 BTW, the code your provide could use some improvements. Perhaps

IF / ELSE和SWITCH代码可以合并到SWITCH / CASE中。

the IF/ELSE and SWITCH code could be merged into SWITCH/CASE.

SWITCH / CASE的基本结构是一系列IF / GOTO语句。

The basic structure of SWITCH/CASE is a series of IF/GOTO statements.

 希望这会有所帮助:)

 Hope this helps :)


这篇关于如何在datagridview中打印所选复选框,以及如果没有选中打印全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆