Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 13-May-11 3:18am    
Always tag it: Forms!
--SA

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;
      }
   }
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()
      { 
      }
   }
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.
 
Share this answer
 
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,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900