如何使用for循环在另一种形式中使用一种形式的文本框值 [英] how to use textbox value of one form in another form using for loop

查看:121
本文介绍了如何使用for循环在另一种形式中使用一种形式的文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在桌面应用程序上工作.我创建了一个带有标签的产品ID,名称,产品编号,目标,预算以及相应文本框的表单.我创建了另一个表单,其中有一个用于输入product_name列表的组合框在第一种形式和文本框中输入特定产品名称的总预算.

例如
第一种形式
第一项

id = 1;
名称=铅笔
产品编号= 500
target = showrooms
预算= 10000

第二个条目
id = 2;
名称=铅笔
产品编号= 50
target = shops
预算= 1000

第三个条目
id = 2;
名称=笔
产品编号= 50
target = shops
预算= 10000

第四次参赛
id = 2;
名称=笔
产品编号= 500
target = showrooms
预算= 100000

现在这里我有4个条目,并且想要第二种形式
预算文本框应包含特定产品名称的所有预算的总和(其中产品名称为铅笔,产品名称为笔)

请帮助我进行编码.hw我可以提前实现this.thanx
问候

I am working on desktop application.i have created one form having labels product id,name,no.of product,target ,budget with respective textboxes.I have created another form in which there is conbo box for list of product_names entered in 1st form and text box for total budget for particular product_name.

e.g.
for 1st form
1st entry

id =1;
name=pencil
no.of product=500
target=showrooms
budget=10000

2nd entry
id =2;
name=pencil
no.of product=50
target=shops
budget=1000

3rd entry
id =2;
name=pen
no.of product=50
target=shops
budget=10000

4th entry
id =2;
name=pen
no.of product=500
target=showrooms
budget=100000

now here i have 4 entries and want in 2nd form
budget textbox should contain sum of all budget for particulat product_name( where product_name is pencil and where product_name is pens)

pls help me for coding .hw can i achieve this.thanx in advance
regards

推荐答案

假设您有权访问这些实例(并且您应该在另一个实例内部创建了一个表单实例),则有两种方法:
1)仅在具有吸气剂的Form1中创建属性,并返回适当类型的列表:
Assuming you have access to the instances (and you should, you probably created one of the form instances inside the other) then there are two ways:
1) Create properties in Form1 with getters only, returning a List of the appropriate types:
public List<int> IDs
   {
   get
      {
      List<int> results = new List<int>;
      results.Add(Entry1IdValue);
      results.Add(Entry2IdValue);
      results.Add(Entry3IdValue);
      results.Add(Entry4IdValue);
      return results;
      }
   }
public List<string> Names
   {
   get
      {
      List<string> results = new List<string>;
      results.Add(Entry1NameValue);
      results.Add(Entry2NameValue);
      results.Add(Entry3NameValue);
      results.Add(Entry4NAmeValue);
      return results;
      }
   }

以此类推.
2)创建一个类,每个类包含一个有价值的信息条目(称为条目).

And so on.
2) Create a class, each holding one entries worth of information (call it Entry).

public Class Entry
   {
   public int ID { get; set; }
   public string Name { get; set; }
   public int NumberOfProduct { get; set; }
   public string Target { get; set; }
   public int Budget { get; set; }
   public Entry()
      { 
      }
   }

然后在Form1中设置一个属性,并返回一个List< Entry>.再次,只有一个吸气剂.

然后,您可以通过Form1实例和属性名称访问数据.

我本人会选择选项2.

Then set up a Property in Form1 returning a List<Entry> with again, only a getter.

You then access the data via the Form1 instance and the property name.

I would go with option 2, myself.




如果我正确理解了您的问题,我认为一种可能的方法是利用Rx(反应性扩展 )[示例]-这样,您可以订阅事件并将结果推送到其他形式,而不必提取结果.

亲切的问候,
Hi,

If I understood your question correctly, I think the one possible approach is to make use of Rx (Reactive Extensions) [Examples] - That way you can subscribe to an event and push the result to the other form, instead of pulling the results.

Kind regards,


这篇关于如何使用for循环在另一种形式中使用一种形式的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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