Your question is not clear, but i'm posting portion of code that may help you......
if (dataGridView1.DataSource != null)
{
DataTable dt = (DataTable)dataGridView1.DataSource;
if (dataGridView1.SelectedRows.Count <= 0) { return; }
if (dt.Rows.Contains(dataGridView1.SelectedRows[0]))
{
DataRow[] dr = dt.Rows.Find(dt.Rows[0]["fieldname"]);
if (dr.Length <= 0) return;
dr[1] = txtName.Text;
dr[2] = txtcity.Text;
dt.AcceptChanges();
dataGridView1.Refresh();
}
}