如何在C#中打印列表视图中的选中项? [英] How to Print the checked items in listview in C# ?

查看:59
本文介绍了如何在C#中打印列表视图中的选中项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我的项目我正在使用ListView名称ListView1



在ListView1中CheckBox ProPerty为True,供用户选择项目。

当点击项目选项并打印按钮时,所选项目应该打印



我的编码:



Hi In My Project I''m Using ListView name "ListView1"

In "ListView1" CheckBox ProPerty is made True , for User to Select the Items .
When Items Selected And Print button is clicked the Selected Items Should Get Print

my coding :

private void BtnBarCode_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem Item in listView1.CheckedItems)
            {
                   BarCodePrint();
			GetQuantity();


            }
        }



        private void BarCodePrint()
        {
            inventoryDS1.BarCode.Clear();
            Connection();
            da = new SqlDataAdapter("select * from DeliveryChallan Where DcNo='"+TbDCNos.Text+"' OR UDcNo='"+TBUDcNo.Text+"'", cs);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow Row in dt.Rows)
                {
                    inventoryDS1.BarCode.ImportRow(Row);
                }
                LoadBcReport();
                ReportBCData();
                string FilePath = Application.StartupPath + "\\BCEndUser.txt";
                XtraReport.BarCoding XRBC = new XtraReport.BarCoding();
                XRBC.LoadLayout(FilePath);
                XRBC.DataSource = inventoryDS1.BarCode;
                XRBC.ShowPreview();
            }
            else
            {
                MessageBox.Show("No BarCode To Print");
            }
            cs.Close();
        }

        private void GetQuantity()
        {
            foreach (ListViewItem Item in listView1.Items)
            {
                for (int BCount = 1; BCount < Convert.ToInt16(Item.SubItems[6].Text); BCount = BCount + 1)
                {
                    DataSet.InventoryDS.BarCodeRow BCR = inventoryDS1.BarCode.NewBarCodeRow();
                    BCR.ModelCode = Convert.ToString(Item.SubItems[1].Text);
                    BCR.ModelName = Convert.ToString(Item.SubItems[2].Text);
                    BCR.ModelSize = Convert.ToString(Item.SubItems[4].Text);
                    BCR.Quantity = Convert.ToString(BCount);
                    BCR.MRPRate = Convert.ToString(Item.SubItems[7].Text);
                    inventoryDS1.BarCode.Rows.Add(BCR);
                }
            }
        }

推荐答案

点击打印后,获取所有标记的项目检查。您可以将它们放在临时数据表中。完成后,使用此临时表打印项目。



逐步尝试。上面的代码是填充而不是选择。在尝试打印之前,您需要找到所选的值。
On print click, get all the items that are marked checked. You can put them in a temporary datatable. Once done, use this temporary table to print items.

Take stepwise and try out. Code above is to populate and not about selection. You need to find selected value before trying to print it.


private void BtnBarCode_Click(object sender,EventArgs e)

{

inventoryDS1.BarCode.Clear();



foreach(listView1.CheckedItems中的ListViewItem项目)

{

if(Item.Checked == true)

{

for(int BCount = 0; BCount< Convert.ToInt16(Item.SubItems [6] .Text); BCount = BCount + 1)

{

DataSet.InventoryDS.BarCodeRow BCR = inventoryDS1.BarCode.NewBarCodeRow();

BCR.ModelCode = Convert.ToString(Item.SubItems [1] .Text);

BCR.ModelName = Convert.ToString(Item.SubItems [2] .Text);

BCR。 ModelSize = Convert.ToString(Item.SubItems [4] .Text);

BCR.Q uantity = Convert.ToString(BCount);

BCR.MRPRate = Convert.ToString(Item.SubItems [7] .Text);

inventoryDS1.BarCode.Rows.Add (BCR);

}

}

}

string FilePath = Application.StartupPath +\\\ \\ BCEndUser.txt;

XtraReport.BarCoding XRBC = new XtraReport.BarCoding();

XRBC.LoadLayout(FilePath);

XRBC .DataSource = inventoryDS1.BarCode;

XRBC.ShowPreview();

}
private void BtnBarCode_Click(object sender, EventArgs e)
{
inventoryDS1.BarCode.Clear();

foreach (ListViewItem Item in listView1.CheckedItems)
{
if (Item.Checked == true)
{
for (int BCount = 0; BCount < Convert.ToInt16(Item.SubItems[6].Text); BCount = BCount + 1)
{
DataSet.InventoryDS.BarCodeRow BCR = inventoryDS1.BarCode.NewBarCodeRow();
BCR.ModelCode = Convert.ToString(Item.SubItems[1].Text);
BCR.ModelName = Convert.ToString(Item.SubItems[2].Text);
BCR.ModelSize = Convert.ToString(Item.SubItems[4].Text);
BCR.Quantity = Convert.ToString(BCount);
BCR.MRPRate = Convert.ToString(Item.SubItems[7].Text);
inventoryDS1.BarCode.Rows.Add(BCR);
}
}
}
string FilePath = Application.StartupPath + "\\BCEndUser.txt";
XtraReport.BarCoding XRBC = new XtraReport.BarCoding();
XRBC.LoadLayout(FilePath);
XRBC.DataSource = inventoryDS1.BarCode;
XRBC.ShowPreview();
}


这篇关于如何在C#中打印列表视图中的选中项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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