c# datagridview Object reference not set to an instance of an object -


i'm taking data entered user , trying add them datagridview in form created, however, i'm having an

object reference not set instance of object. when try add first row,

this code below:

    monthtrans mt = new monthtrans();     private void completebtn_click(object sender, eventargs e)     {         var todaydate = datetime.now;         //messagebox.show(todaydate.tostring());         var transtype = typelabel.text;         var currencyselected = currencylist.text;         var amount = amounttext.text;         var currencyprice = currencypricetext.text;         var total = totalamounttext.text;          var monthlydata = mt.mydata;          monthlydata.rows.add(todaydate, transtype, currencyselected, amount, currencyprice, total);          //open new window         mt.parent = parent;         mt.startposition = formstartposition.centerparent;         if (mt.isdisposed)               mt = new monthtrans();         mt.show();     } 

the error appears on "monthlydata.rows.add......."

btw, added in datagridview form code below access outside form:

    public datagridview mydata     {         get;         set;     } 

thanks help

try:

private datagridview _mydata = new datagridview(); public datagridview mydata {     { return _mydata; }     set { _mydata = value; }  } 

Comments