从类+ C#访问listview的项目 [英] access items of listview from a class + C#

查看:72
本文介绍了从类+ C#访问listview的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个windows窗体frmPurchase,其中包含一个lisview(purchaseListView)。

i也有一个类purchase.cs,其中包含调用存储过程的函数。

i想要在list.cs中获取listview的项目作为存储过程的参数。

我该怎么办?



问候

bunzitop

i have a windows form frmPurchase which contains a lisview (purchaseListView).
i also have a class purchase.cs which contains function that calls stored procedure.
i want to get the items of listview as parameters of stored procedure in class purchase.cs
how can i do it?

regards
bunzitop

推荐答案

你必须做这样的事情..

1.使你的购买类变化。

2.使用循环从列表视图中检索项目

3.use Item.Text检索值

4.将该值传递给购买方法.cs



例如

u have to do something like this..
1.Make variable of ur purchase class.
2.Use for loop to retrieve item from listview
3.use Item.Text to retrieve value
4.pass that values to method of purchase.cs

for example
purchase objPuchase = new purchase();
string value1;
string value2;
foreach (ListViewItem item in purchaseListView.Items)
{
    value1 =  item.SubItems[0].Text.ToString();
    value2 =  item.SubItems[1].Text.ToString();
//repeat it for all 10 rows
    objPuchase.UrStoreProcedureMethodName(value1 ,value2);
}



希望它能帮助


hope it will help


另一种解决方案是使用它创建一个新的类项目获取和设置值属性。

和购买类创建类型项列表的通用变量。

将此值传递给项类。

在你的商店程序方法中从列表中迭代此值并传递给存储过程作为参数..exampal

1.create item calss

another solution is create one new class items using it get and set values by property.
and in purchaseclass create generic variable of list of type item .
pass this values to item class.
In ur store procedure method iterate this values from list and pass to store procedure as parameter ..exampal
1.create item calss
public class Item
    {
        string name;
        string lname


        public Item(string name, string lname)
        {
            this.name = name;
            this.lname = lname;

        }



        public string Name
        {
            get
            {
                return this.name;
            }
        }
        public string MyLname
        {
            get
            {
                return this.lanme;
            }
        }

    }





2.在列表视图页面中传递此值物品



2.In listview page pass this values to items

purchase  objpurchase =new purchase();
foreach (ListViewItem item in purchaseListView.Items)
{
    value1 =  item.SubItems[0].Text.ToString();
    value2 =  item.SubItems[1].Text.ToString();
//repeat it for all 10 rows
    objPuchase.Items.Add( new Item(value1,value2));
}





3.更改你的购买类创建泛型变量作为public类型Items类的列表并从中迭代值。



3.change ur purchase class create generic variable as public List of type Items class and iterate values from it.

public class purchase
    {
        public List<Item> Items;

        double InvoiceTotal;

        public Invoice()
        {
            Items = new List<Item>();
        }



        public void StoreProcedureMethos()
        {
        string name2;
        string lanme2;
             foreach (Item i in this.Items)
                {
                    name2=i.Name;
                    lanme2=i.MyLname;
            //ur store procedure code pass this as parameter to it

                }


        }

    }





尝试一下作为演示...根据您的要求进行更改



try it as demo ...change as per ur requirements


这篇关于从类+ C#访问listview的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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