title: How to add rows to a RadGridView in WinForms using c#
body: <p>I am trying to add a rows to a RadGridView when a use click a button on the form (ie. "Add".)</p>
  
  <p>When the form load I add columns to the <code>RadGridView</code> and make all of them all ReadOnly except one .</p>
  
  <p>When a user click the "Add" button, I want to add a row to this RadGridView. Basically, a user types a UPC code, then I read data from the database and add new row in a grid view with the item name, item price.</p>
  
  <p>Here is what I did to create the columns</p>
  
  <p>private void Register_Load(object sender, EventArgs e) {</p>
  
  <pre><code>        GridViewTextBoxColumn UPC = new GridViewTextBoxColumn();
          UPC.Name = "UPC";
          UPC.HeaderText = "UPC";
          UPC.FieldName = "UPC";
          UPC.MaxLength = 50;
          UPC.TextAlignment = ContentAlignment.BottomRight;
          radGridView1.MasterTemplate.Columns.Add(UPC);
          radGridView1.Columns["UPC"].Width = 120;
          radGridView1.Columns["UPC"].ReadOnly = true;
  
          GridViewTextBoxColumn ItemName = new GridViewTextBoxColumn();
          ItemName.Name = "Item Name";
          ItemName.HeaderText = "Item Name";
          ItemName.FieldName = "ItemName";
          ItemName.MaxLength = 100;
          ItemName.TextAlignment = ContentAlignment.BottomRight;
          radGridView1.MasterTemplate.Columns.Add(ItemName);
          radGridView1.Columns["Item Name"].Width = 210;
          radGridView1.Columns["Item Name"].ReadOnly = true;
  
          GridViewDecimalColumn QtyColumn = new GridViewDecimalColumn();
          QtyColumn.Name = "Qty";
          QtyColumn.HeaderText = "Quantity";
          QtyColumn.FieldName = "Qty";
          QtyColumn.DecimalPlaces = 1;
          radGridView1.MasterTemplate.Columns.Add(QtyColumn);
          radGridView1.Columns["Qty"].Width = 75;
  
          GridViewMaskBoxColumn PriceColumn = new GridViewMaskBoxColumn();
          PriceColumn.Name = "Unit Price";
          PriceColumn.FieldName = "UnitPrice";
          PriceColumn.HeaderText = "Unit Price";
          PriceColumn.MaskType = MaskType.Numeric;
          PriceColumn.Mask = "C";
          PriceColumn.TextAlignment = ContentAlignment.BottomRight;
          PriceColumn.FormatString = "{0:C}";
          PriceColumn.DataType = typeof(decimal);
          radGridView1.MasterTemplate.Columns.Add(PriceColumn);
          radGridView1.Columns["Unit Price"].Width = 75;
          radGridView1.Columns["Unit Price"].ReadOnly = true;
  
          GridViewMaskBoxColumn TotalColumn = new GridViewMaskBoxColumn();
          TotalColumn.Name = "Total Price";
          TotalColumn.FieldName = "TotalPrice";
          TotalColumn.HeaderText = "Total Price";
          TotalColumn.MaskType = MaskType.Numeric;
          TotalColumn.Mask = "C";
          TotalColumn.TextAlignment = ContentAlignment.BottomRight;
          TotalColumn.FormatString = "{0:C}";
          TotalColumn.DataType = typeof(decimal);
          radGridView1.MasterTemplate.Columns.Add(TotalColumn);
          radGridView1.Columns["Total Price"].Width = 75;
          radGridView1.Columns["Total Price"].ReadOnly = true;
  
  
      }
  </code></pre>
  
  <p>To add the row Here is what I am doing "when a user click the 'Add' button)</p>
  
  <pre><code>private void ButtonAdd_Click(object sender, EventArgs e) {
  
  
              string UPC = InputUPC.Text.Trim();
  
              if (UPC.Length &lt; 3) {
                  return;
              }
  
              string sql = " SELECT p.productName, p.price "
                         + " FROM products AS p "
                         + " WHERE p.productUPC = @upc ";
  
              var parms = new List&lt;MySqlParameter&gt;();
              parms.Add(new MySqlParameter("@upc", UPC));
  
              var db = new dbConnetion();
  
              foreach (var i in db.getData(sql, parms, r =&gt;
                                                  new ProductsTable() {
                                                      _productName = r["productName"].ToString(),
                                                      _price = Convert.ToDouble(r["price"])
                                                  }
                                           )
              ) {
  
                  //radGridView1.Rows[0].Cells[0].Value = 4.3;
                  radGridView1.Rows[0].Cells["UPC"].Value = UPC;
                  radGridView1.Rows[0].Cells["Item Name"].Value = i._productName;
                  radGridView1.Rows[0].Cells["Qty"].Value = "1";
                  radGridView1.Rows[0].Cells["Unit Price"].Value = i._price;
                  radGridView1.Rows[0].Cells["Total Price"].Value = (Convert.ToDouble(i._price) * Convert.ToInt32(radGridView1.Rows[0].Cells["Qty"].Value)).ToString();
              }
          }
  </code></pre>
  
  <p>But the add row is giving me an error</p>
  
  <pre><code>Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index
  </code></pre>
  
  <p>How can I correctly add rows to the RadGridView when the "Add" button is clicked.</p>