-2

I am developing a field farm software. There are 3 forms: form1, form2, form3.

form1 is just a welcome page then when you proceed to form2, its a data collection, where inputs are collected from textboxes and then multiplied at background and displayed on form3.

ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
RC-AI
  • 114
  • 1
  • 12

1 Answers1

0

The crude horrible way to do that is you could have on Form3, 14 different public facing properties.

public string textboxValue1;
public string textboxValue2;
public string textboxValue3;
etc...

Then when you new up Form3, you'll have access to these and pass the data that way.

so:

Form3 form3 = new Form3();
form3.textboxValue1 = fieldValue1;
form3.textboxValue2 = fieldValue2;
form3.textboxValue3 = fieldValue3;
etc..
form3.ShowModal();
form3.Dispose();

Ideally you should be using a business object / model. You've already mentioned 14 rows and 4 columns, so your model might look something like this:

public class modelname
{
  public datatype column1fieldname { get; set; }
  public datatype column2fieldname { get; set; }
  public datatype column3fieldname { get; set; }
  public datatype column4fieldname { get; set; }
}

where datatype is string, int, decimal or whatever value types your using, and column_n_fieldname relates to something sensible in your object!

On form2 you can have a private property:

private List<modelname> capturedData;

in the constructor - new it up so:

public Form2()
{
  InitializeComponent();

  capturedData = new List<modelname>();
}

when the user clicks to form3, you can stuff your data from the textboxes into the model -> then pass the model to form3 to do whatever you want with it.

so on form2 you might have a couple of methods like:

private void CollectData()
{
  capturedData.Clear();

  AddRowData(yourrow1column1value, yourrow1column2value, yourrow1column3value, yourrow1column4value);  // Row 1
  AddRowData(yourrow2column1value, yourrow2column2value, yourrow2column3value, yourrow2column4value);  // Row 2
  // etc...
}

private void AddRowData(datatype column1data, datatype column2data, datatype column3data, datatype column4data)
{
  capturedData.Add(new modelname() { column1fieldname = column1data, column2fieldname = column2data, column3fieldname = column3data, column4fieldname = column4data});
}

Form3's constructor might be:

public Form3(List<modelname> capturedData)
{
  InitializeComponent();

  // Then whatever you want to do with it...
}
Scott
  • 180
  • 6
  • thanks but actually cant understand this – RC-AI Aug 07 '17 at 08:41
  • What bit don't you understand? There are two solutions above... one horrible crude noob way to do what you want (first 2 code blocks), and one more technically correct using a business model (simply a class where you would store a row's piece of data), which you can then pass onto form 3 for it's manipulated view. You could even pass this row into some business logic that converts the data into the manipulated view for you ready to pass onto form3. – Scott Aug 09 '17 at 10:36