adding new row to datagrid view programmatically
<p>I Have a datagridview that gets data from database and shows to the user,I also have three textboxes through which user can enter the value into the datagrid view if I select an already existing row in the datgrid and then enter value by text boxes it makes the changes and when I push change button changes are made successfully in both db and the datagridview
but if I select an empty row in the datagrid view and try to enter the values I cannot new row is not added to the datagrid view although allow user to add new row is set to true.</p>

<pre><code> private void txtName_TextChanged(object sender, EventArgs e)
{
    if (dataGridView1.SelectedRows.Count == 1)
    {
        dataGridView1.SelectedRows[0].Cells["Name"].Value = txtName.Text;
    }
}

private void txtRelation_TextChanged(object sender, EventArgs e)
{
    if (dataGridView1.SelectedRows.Count == 1)
    {
        dataGridView1.SelectedRows[0].Cells["Relation"].Value = txtRelation.Text;
    }
}
private void txtID_TextChanged(object sender, EventArgs e)
{
    if (dataGridView1.SelectedRows.Count == 1)
    {
        dataGridView1.SelectedRows[0].Cells["ID"].Value = txtID.Text;
    }

}
</code></pre>
