title: Object reference not set to an instance of an object. when binding datatable to datagridview in c #
body: <p>I Want to save multiple value from  window form to <strong>datatable</strong>  and then  i bind this table to <strong>Datagridview</strong>. Value are adding in <code>Datatable</code> but At:</p>
  
  <pre><code>dataGridViewX1.DataSource = dt.DefaultView.Table);
  </code></pre>
  
  <p>binding point error shows</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>How Can I solve it?</p>
  
  <pre><code>public AddOrder(string ItemName,int Qty,Double Price)
      {
  
  
          try
          {
              DataTable dt = new DataTable();
              dt.Columns.Add("id");
              dt.Columns.Add("Item Name");
  
              dt.Columns.Add("Qty");
              dt.Columns.Add("Unit Price");
              dt.Columns.Add("Amounts");
  
  
              DataRow dr = dt.NewRow();
              dr["id"] = a;
              a++;
  
              dr["Item Name"] = ItemName;
              dr["Qty"] = Qty;
              dr["Unit Price"] = Price;
              dr["Amounts"] = (Convert.ToInt32(dr["Qty"]) * Convert.ToInt32(dr["Unit Price"]));
              dt.Rows.Add(dr);
  
              dataGridViewX1.DataSource = dt.DefaultView.Table;
  
          }
          catch(Exception ee)
          {
              DevComponents.DotNetBar.MessageBoxEx.Show(ee.Message,"Error Message");
          }
      }
  </code></pre>