title: Edit DataGridView selected row
body: <p>I have a datagridview that contains personal information of the user. My datagridview is being populated by the data retrieve from the database. after populating the datagridview, I've added 2 DatagridViewLinkColunm. One is for editing the content of the selected row and the other is for saving the changes made. What I want to achieve is that, if the user select a row and click "Edit" link label, the selected row will be edited (BeginEdit = true). But if the user select another row and he/she dont click the Save button, a MessageBox will appear asking wether the user want to save the changes or not.</p>
  
  <p>I've tried getting the current row and current column in the CellEnter event and checking the current and previous row selected in CellContentClick event but I didnot achieve what I want.</p>
  
  <p>Below is the code...</p>
  
  <pre><code>private void DataGridViewUserList_CellEnter(object sender, DataGridViewCellEventArgs e)
      {
          currentRow = e.RowIndex;
          currentColumn = e.ColumnIndex;
  
      }
  
  private void DataGridViewUserList_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
          if (currentColumn == 6)
          {
              if (rowNumberToBeEdited &lt; 0)
              {
                  rowNumberToBeEdited = e.RowIndex;
                  goto EnableEditing;
              }
  
              if (rowNumberToBeEdited != e.RowIndex)
              {
                  DialogResult dialogResult = MessageBox.Show("Do you want to save the changes you've made", "ACOS-LITE Multi-Application Demo", MessageBoxButtons.YesNo);
  
                  if (dialogResult == DialogResult.Yes)
                  {
                      // save data
                  }
  
                  rowNumberToBeEdited = e.RowIndex;
              }
  
          EnableEditing:
              DataGridViewUserList.CurrentCell = DataGridViewUserList[1, currentRow];
              DataGridViewUserList.BeginEdit(true);
  
              DataGridViewUserList.CurrentCell = DataGridViewUserList[2, currentRow];
              DataGridViewUserList.BeginEdit(true);
  
              DataGridViewUserList.CurrentCell = DataGridViewUserList[3, currentRow];
              DataGridViewUserList.BeginEdit(true);
  
              DataGridViewUserList.CurrentCell = DataGridViewUserList[4, currentRow];
              DataGridViewUserList.BeginEdit(true);
          }
  
  
      }
  </code></pre>