'First row is selected by default upon form loading

 private void FormatdgvParts(DataGridView d)
    {
        d.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        d.MultiSelect = false;
        d.ReadOnly = true;
        d.RowHeadersVisible = false;
        d.AllowUserToAddRows = false;
    }

    private void FormatdgvProds(DataGridView d)
    {
        d.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        d.MultiSelect = false;
        d.ReadOnly = true;
        d.RowHeadersVisible = false;
        d.AllowUserToAddRows = false;
    }

    private void Display()
    {
        dgvParts.AutoGenerateColumns = true;
        dgvParts.DataSource = Inventory.AllParts;
        dgvProds.AutoGenerateColumns = true;
        dgvProds.DataSource = Inventory.Products;
    }

    public Form1()
    {
        InitializeComponent();
        FormatdgvParts(dgvParts);
        FormatdgvProds(dgvProds);
        Display();
    }

Any ideas on how to not get the first row selected when it loads?

I've tried d.CurrentRow.Selected = false; - threw an exception

d.Rows[0].Selected = false; - threw same exception



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source