如何在C#中将字符串值列表从一个表单传递到另一个表单? [英] How Can I pass a List of string values from one Form to another in C#?

查看:141
本文介绍了如何在C#中将字符串值列表从一个表单传递到另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have list of string values pass form one to another form the same list of string values. 

推荐答案

请参阅此链接 http://stackoverflow.com/questions/12768674/send-data-from-one-page-to-another-in-c-sharp -asp-net [ ^ ]


参考这些链接。



< a href =http://www.codeproject.com/Articles/17371/Passing-Data-between-Windows-Forms>在Windows窗体之间传递数据 [ ^ ]



http://stackoverflow.com/questions/7886544/从一种形式传递到另一种形式的价值 [ ^ ]
Refer these links.

Passing Data between Windows Forms[^]

http://stackoverflow.com/questions/7886544/passing-a-value-from-one-form-to-another-form[^]


根据您的场景,我创建了一个示例,让您了解我们如何将字符串集合从一个表单传递到另一个表单: -



让我说有两种形式如下: -

ContainForm:保存需要发送的数据。

GetForm:从ContainForm获取数据的表格。



现在我们可以在GettingForm中拥有属性来设置stringcollection,然后再从第一个表单打开表单。



GettingForm.cs

--------------

As per your scenario i have created an example to get you understand how we can pass string collection from one form to another :-

Let say i have two forms as below :-
ContainForm : Holds data which needs to be send.
GettingForm : Form which gets data from ContainForm.

Now we can have property in GettingForm to set the stringcollection before opening the form from first form.

GettingForm.cs
--------------
public partial class GettingForm : Form
    {
        public StringCollection DummyList { get; set; }

        public GettingForm()
        {
            InitializeComponent();
        }

        private void GettingForm_Load(object sender, System.EventArgs e)
        {
            foreach (string str in this.DummyList)
            {
                MessageBox.Show(str);
            }
        }
    }





ContainForm.cs

- --------------



ContainForm.cs
---------------

public partial class ContainForm : Form
    {
        public StringCollection DummyList { get; set; }

        public ContainForm()
        {
            InitializeComponent();
        }

        private void ContainForm_Load(object sender, System.EventArgs e)
        {
            DummyList = new StringCollection();
            DummyList.Add("Item 1");
            DummyList.Add("Item 2");
            DummyList.Add("Item 3");
            DummyList.Add("Item 4");
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            GettingForm gtForm = new GettingForm(); // create instance of GettingForm
            gtForm.DummyList = this.DummyList; // Assign value to the string collection propery of GettingForm
            gtForm.Show(); // Display the form
        }
    }







希望这对你有所帮助。



那里您也可以获得更多替代方案此处 [ ^ ]。


这篇关于如何在C#中将字符串值列表从一个表单传递到另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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