如何以C#中的另一种形式在Listview上显示结果 [英] How to display the result on Listview in the other form in C#

查看:81
本文介绍了如何以C#中的另一种形式在Listview上显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人
我在以其他形式在列表视图中显示数据时遇到问题.有2种形式.在form1中,我添加了要在ListView中显示的数据,单击它时有一个显示"按钮,它将与form2一起弹出.我想要在相同的数据显示在带有Form1的ListView中.但我不知道该怎么做?请帮帮我.

Dear all
I have a problem with displaying data in listview in other form. there are 2 form. In form1 I add data to display in ListView and there is a Show button when click on it, it will popup with form2. And I want the same data display in ListView with form1. but I don''t know how to do it? Please help me.

Thank you in advance.

推荐答案

最简单的方法是在第二种形式的构造函数中提供信息,或者以您设置的第二种形式提供属性.从第一个开始,在调用Show方法(或ShowDialog)之前:
The easiest ways are to either provide the information in the constructor of the second form, or to provide properties in teh second form which you set from the first, prior to the Show method (or ShowDialog) being called:
public MySecondForm(string name, int age)
   {
   textBoxWithName.Text = name;
   textBoxWithAge.Text = age.ToString();
   }

...

   MySecondForm msf = new MySecondForm("John Smith", 27);
   msf.Show();


public string Name
   {
   get { return textBoxWithName.Text; }
   set { textBoxWithName.Text = value; }
   }
public int Age)
   {
   get { return int.Parse(textBoxWithAge.Text); }
   set { textBoxWithAge.Text = age.ToString(); }
   }

...

   MySecondForm msf = new MySecondForm();
   msf.Name = "John Smith";
   msf.Age = 27;
   msf.Show();


这篇关于如何以C#中的另一种形式在Listview上显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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