I figured out one way of doing it by following below steps
1) Add below mentioned method to your code
private void MakeOnlyCurrentRowVisible()
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.CurrentRow != dataGridView1.Rows[i])
dataGridView1.Rows[i].Visible = false;
}
}
2)Add VisibleChanged event handler to your Form like given below
private void Form3_VisibleChanged(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = false;
MakeOnlyCurrentRowVisible();
}
3) Add code to dataGridView1_SelectionChanged event like below
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (!dataGridView1.AllowUserToAddRows)
{
MakeOnlyCurrentRowVisible();
}
}
Hope it will help.