1

I have to pass id from one form to another from in C#.

I am not able to do this.

The C# code is:

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");
        }
    }
}

Can anybody tell me what I am doing wrong?

2 Answers 2

5

Make a property in AddInvoice:

public long CellValue { get; set }

Assign to it:

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");
        }
    }

And just use it in AddInvoice as CellValue.

Oh, and if that's actually the code, I think you probably meant this.Hide(); instead of creating a new NonPaideData and hiding that.

Sign up to request clarification or add additional context in comments.

Comments

4

In Form1

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

In Form2

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

    }
}

See this code i think this will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.