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;//默认选中第一行
        }在这里插入代码片
发布了125 篇原创文章 · 获赞 29 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_40486955/article/details/98071962
今日推荐