通过表单中的方法以另一种形式将项目添加到Listview

时间:2014-02-19 06:37:01

标签: c# .net winforms listview

我正在尝试将某些值传递给另一种形式的方法,此方法适用于在此窗体中向listView添加一些值。它似乎有效,因为没有错误消息。有人可以帮助我在哪里弄错了吗?谢谢你的回复!

我的代码如下:

public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }     

  public void AddToTaskMan(string tarih, string gorevturu, string barkod, string actiondate, string actionid, string actionreasonid, string courieragentname, 
            string courieragentcode, string courierregionname, string courierregioncode, string courierstaffname, string courierstaffcode, string tarih1, string tarih2)
        {

            try
            {
                Int32 i = listView1.Items.Count;
                listView1.Items.Add(i.ToString());
                listView1.Items[i].SubItems.Add(tarih);
                listView1.Items[i].SubItems.Add(gorevturu);
                listView1.Items[i].SubItems.Add(barkod);
                listView1.Items[i].SubItems.Add(actiondate);
                listView1.Items[i].SubItems.Add(actionid.ToString());
                listView1.Items[i].SubItems.Add(actionreasonid);
                listView1.Items[i].SubItems.Add(courieragentname);
                listView1.Items[i].SubItems.Add(courieragentcode);
                listView1.Items[i].SubItems.Add(courierregionname);
                listView1.Items[i].SubItems.Add(courierregioncode);
                listView1.Items[i].SubItems.Add(courierstaffname);
                listView1.Items[i].SubItems.Add(courierstaffcode);
                listView1.Items[i].SubItems.Add(tarih1);
                listView1.Items[i].SubItems.Add(tarih2);


            }
            catch
            {

            }
        }


public partial class frmAddTask : Form
    {
        public frmAddTask()
        {
            InitializeComponent();
        }


        private void btnAdd_Click(object sender, EventArgs e)
        {
            string gorevturu;

            DateTime datetime_ = new DateTime();
            datetime_ = DateTime.Now;


            frmMain main = new frmMain();

            if (radioButton1.Checked)
            {
                gorevturu = "1";

                main.AddToTaskMan(Convert.ToString(datetime_), gorevturu, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", txtDate1.ToString(), txtDate2.ToString());
            }
            else
            {
                gorevturu = "2";
                main.AddToTaskMan(Convert.ToString(datetime_), gorevturu, txtBarcode.ToString(), txtActionDate.ToString(), txtActionID.ToString(), txtReasonID.ToString(), txtCourierAgentName.ToString(), txtCourierAgentCode.ToString(), txtRegionName.ToString(), txtRegionCode.ToString(), txtStaffName.ToString(), txtStaffCode.ToString(), "-", "-");
            }


        }

0 个答案:

没有答案