2017-07-05 4 views
0

必要なすべてのデータをあるフォームから別のフォームに渡す際に問題があります。以下は、渡したいデータを見ることができますが、何が起こるかは、(_12nc、BID、device、orderNr)だけですが、リスト<>ステップは通過しません。私は手順よりも、唯一の一覧<>の手順を渡そうC#すべてのデータがあるフォームから別のフォームに渡されるわけではありません。

Steps stepsForm = new Steps(ref steps, _12nc, BID, device, orderNr);  

しかし渡されます

Steps stepsForm = new Steps(ref steps) 

は、どのように私はリストと個々の値の両方を渡すことができますか?

これは私がデータを渡したい場所からのコードです:

private void btn_start_Click(object sender, EventArgs e) 
    { 
     List<Step> steps = new List<Step>(); 
     int device; 
     string _12nc; 
     int BID; 
     int orderNr; 

     device = Convert.ToInt32(txt_device.Text); 
     _12nc = txt_12nc.Text; 
     BID = Convert.ToInt32(txt_BID.Text); 
     orderNr = Convert.ToInt32(txt_OrderNr.Text); 

     // Get list of steps (ID and Description) 
     steps = myDBHelper.GetSteps(_12nc,device, BID);   

     // Open new form and pass steps to it 
     Steps stepsForm = new Steps(ref steps, _12nc, BID, device, orderNr); //, _12nc, BID, device, orderNr 
     stepsForm.Show(); 
     this.Hide(); 
    } 

そして、これは私がそれを渡したいところです:あなたの要件ごとに

public partial class Steps : Form 
{ 
    private List<Step> steps = new List<Step>(); 
    private List<Parameter> param = new List<Parameter>(); 

    private String _12nc; 
    private int BID; 
    private int device; 
    private int orderNr; 


    public Steps(ref List<Step> steps, string _12nc, int BID, int device, int orderNr) 
    { 
     InitializeComponent(); 
     this.steps = steps; 
     this._12nc = _12nc; 
     this.BID = BID; 
     this.device = device; 
     this.orderNr = orderNr; 
     RefreshLabels(); 
    } 
+0

あなたがそれを渡す場合は、2番目のフォーム、その渡された期間。 'List <> steps'ではなく、あなたの前提です – EpicKip

+0

はい、私はステップがいっぱいであることがわかります –

+0

あなたはrefでListを渡す必要はありません、あなたの問題は解決していると思いますか? –

答えて

0

コード以下の修正、私が持っていますそれが正常に動作していることを確認します。

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     List<Step> steps = new List<Step>(); 
     Step objStep = new Step(); 
     int device; 

     device = 32; 
     objStep._12nc = "dsfdsF"; 
     objStep.BID = 3; 
     objStep.orderNr = 12; 

     // Get list of steps (ID and Description) 
     //steps = myDBHelper.GetSteps(_12nc, device, BID); 
     steps.Add(objStep); 
     // Open new form and pass steps to it 
     Form2 stepsForm = new Form2(steps, objStep, device); //, _12nc, BID, device, orderNr 
     stepsForm.Show(); 
     this.Hide(); 
    } 
} 

public partial class Form2 : Form 
{ 
    public Form2() 
    { 
     InitializeComponent(); 
    } 
    private List<Step> steps = new List<Step>(); 
private List<Parameter> param = new List<Parameter>(); 

private String _12nc; 
private int BID; 
private int device; 
private int orderNr; 


public Form2(List<Step> steps, Step objStep, int device) 
{ 
    InitializeComponent(); 
    this.steps = steps; 
    this._12nc = objStep._12nc; 
    this.BID = objStep.BID; 
    this.device = device; 
    this.orderNr = objStep.orderNr; 
    //RefreshLabels(); 
} 
} 
public class Step 
{ 
    public string _12nc { get; set; } 
    public int BID { get; set; } 
    public int orderNr { get; set; } 
} 
public class Parameter 
{ 
} 
+0

ありがとう、それは働いた:) –

関連する問題