2012-08-04 81 views
1

我必须在C#中将id从一个窗体传递到另一个窗体。将值从一个窗体传递到另一个窗体在c#

我无法做到这一点。

的C#代码:

private void btnedit_Click(object sender, EventArgs e) 
{ 
    foreach (DataGridViewRow a in dataGridViewUnPaidList.Rows) 
    { 
     if (a.Cells[0].Value != null) 
     { 
      Convert.ToInt64(a.Cells[1].Value); // i have to pass this id in AddInvoice() form 
      AddInvoice ad = new AddInvoice(); 
      ad.Show(); 
      NonPaideData non = new NonPaideData(); 
      non.Hide(); 
     } 
     else 
     { 
     MessageBox.Show("Now Row Is Selected"); 
     } 
    } 
} 

谁能告诉我什么,我做错了什么?

回答

3

在Form1

private void ShowForm2() 
{ 
    string value = TheTextBox.Text; 
    Form2 newForm = new Form2(); 
    newForm.TheValue = value; 
    newForm.ShowDialog(); 
} 

在窗体2

private string _theValue; 
public string TheValue 
{ 
    get 
    { 
     return _theValue; 
    } 
    set 
    { 
     _theValue = value; 
     // do something with _theValue so that it 
     // appears in the UI 

    } 
} 

看到这个代码,我认为这会帮助你。

5

使属性在AddInvoice

public long CellValue { get; set } 

分配给它:

private void btnedit_Click(object sender, EventArgs e) 
{ 
    foreach (DataGridViewRow a in dataGridViewUnPaidList.Rows) 
    { 
     if (a.Cells[0].Value != null) 
     { 
      AddInvoice ad = new AddInvoice(); 
      ad.CellValue = Convert.ToInt64(a.Cells[1].Value); 
      ad.Show(); 

      NonPaideData non = new NonPaideData(); 
      non.Hide(); 
     } 
     else 
     { 
      MessageBox.Show("Now Row Is Selected"); 
     } 
    } 

,只是使用它作为AddInvoiceCellValue

哦,如果这实际上是代码,我想你可能意思是this.Hide();而不是创建一个新的NonPaideData并隐藏它。

相关问题