title: Delete a row from Datagrid view and also from object in windows forms
body: <p>I have a form with a datagridview which gets populated from an object in another class (basically this object acts like a database throughout the application). The selected row gets deleted when user clicks a button. The row should be deleted from dgv and also from that object.</p>
  
  <p>There is also a search criteria which will reduce the number of rows displayed in dgv. Now when user opts for this search and selects a row from reduced number of rows, I am not able to handle the delete row logic. </p>
  
  <p>Currently I am having the row number in INT variable and deleting the same instance in object list. I know this wont work when rows are reduced. Thanks in advance for your help. </p>
  
  <p>In form :</p>
  
  <pre><code>private void btnDelete_Click(object sender, EventArgs e)
  {
  class obj=new class();
  int row = dataGridView1.CurrentCell.RowIndex;
  obj.deleteName(row);
  dataGridView1.Rows.RemoveAt(row);
  }
  </code></pre>
  
  <p>In class:</p>
  
  <pre><code>class Class
  {
  List&lt;string&gt; names=new list&lt;string&gt;();
  
  public void deleteName(int index)
  {
  names.RemoveAt(index);
  }
  
  }
  </code></pre>