title: Add New Rows Datagridview by linq
body: <p>I'm trying to add new new rows to dataGrid pragmatically.First the code checks to see if the row doesnt already exist, and if not ,it puts new row ; Otherwise it doesn't enter the row in the DatagridView </p>
  
  <p>The problem with my code is that it continuous loops ,adding the same Rows when Events Trigger.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> public static void addJobstoDespatchGrid(DataGridView jobDataGridView)
      {
          using (DBEntities db = new DBEntities())
          {
              var data = (from a in db.Active where a.Status == "Hold"
                                                   select a);
  
  
              foreach (var row in Data)
              {
                  if (GridView.RowCount &gt;= 0)
                  {
                      foreach (DataGridViewRow r in GridView.Rows)
                      {
  
                          Int32 id = Convert.ToInt32(r.Cells[0].Value);
  
                          if (row.jobID !=id)
                          {
                              DataGridViewRow rw = new DataGridViewRow();
                              rw.CreateCells(GridView);
                              rw.Cells[0].Value = row.jobID;
                              rw.Cells[1].Value = row.JobType;
                              rw.Cells[2].Value = row.dateTime;
                              rw.Cells[3].Value = row.jobStatus;
  
                              GridView.Rows.Add(rw);
  
                          }
                      }
                  }
                  else
                  {
                      DataGridViewRow rw = new DataGridViewRow();
                      rw.CreateCells(GridView);
                      rw.Cells[0].Value = row.jobID;
                      rw.Cells[1].Value = row.JobType;
                      rw.Cells[2].Value = row.dateTime;
                      rw.Cells[3].Value = row.jobStatus;
  
  
                     GridView.Rows.Add(rw);
  
                  }
              }
          }
      }
  </code></pre>