1

I have Gridview in my Form, If i click button on the Gridview I get Column value of Focused Row and Try to use that Value in next Form. But in that new form error shown like this

 public partial class New_Invoice : DevExpress.XtraEditors.XtraForm
{

    string getOper = "A";

    public New_Invoice()
    {
        InitializeComponent();
    }

    public New_Invoice(string oper, int invoiceno)
    {
        // TODO: Complete member initialization

        textEdit5.Text = invoiceno.ToString(); // error shown in this line
        textEdit5.Visible = false;
        getOper = oper;
    }  

What was wrong in my code ?

1 Answer 1

5

In your custom constructor you aren't calling InitializeComponent(). This is critical: this is what creates the controls. A simple fix might be to chain the constructor (see the : this()):

public New_Invoice(string oper, int invoiceno) : this()
{
    textEdit5.Text = invoiceno.ToString(); // error shown in this line
    textEdit5.Visible = false;
    getOper = oper;
} 

However, personally I would advise against adding custom constructors to forms / controls, and instead use properties / methods on the newly created instance, so the caller does something like:

using(var form = new NewInvoice())
{
    form.Operation = ...;     // (or maybe form.SetInvoiceNumber(...) if the
    form.InvoiceNumber = ...; // logic is non-trivial)
    // show the form, etc
}
Sign up to request clarification or add additional context in comments.

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.