天天看点

datagridview默认选中第一行方法

设置datagridview在加载时默认选中第一行:

在需要为datagridview加载数据的地方添加代码:

this.dataGridView1.Rows[0].Selected = true;
           

例如

private void deplane_Load(object sender, EventArgs e)
        {
           
            // TODO: 这行代码将数据加载到表“charge_sysDataSet.OnLine_Info”中。您可以根据需要移动或删除它。
            this.onLine_InfoTableAdapter.Fill(this.charge_sysDataSet.OnLine_Info);
            dataGridView1.AllowUserToAddRows = false;  //去除空白行
          dataGridView1.Rows[0].Selected = true;//默认选中第一行
        }在这里插入代码片