datagridview取消默认选中_C# WinForm 取消DataGridView的默认选中Cell 使其不反蓝
dataGridView1.Rows[0].Selected = false;
默認(rèn)情況下 DataGridView綁定數(shù)據(jù)后
會(huì)選中首行首列
為實(shí)現(xiàn)其沒有默認(rèn)不選中(即綁定后 看不到首行首列反藍(lán))
之前將
dataGridView1.Rows[0].Selected = false;
放在窗體的構(gòu)造函數(shù)中 怎么都看似不起效果 首行首列還是反藍(lán)
后來嘗試放在窗體的Load中 終于看不不反藍(lán)了
同時(shí)需要注意dataGridView1的TabIndex
相關(guān)代碼如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2");
dt.Columns.Add("Column3");
DataRow dr = dt.NewRow();
dr["Column1"] = "1";
dr["Column2"] = "2";
dr["Column3"] = "3";
dt.Rows.Add(dr);
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = dt;
//dataGridView1.Rows[0].Selected = false; //放在Form1這里不起效果 可放在下面的Form1_Load中
this.button1.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows[0].Selected = false;
//this.dataGridView1.TabStop = false;
//dataGridView1.Rows[0].Selected = false;
//this.dataGridView1.CurrentCell = null;
//dataGridView1.ClearSelection();
}
}
總結(jié)
以上是生活随笔為你收集整理的datagridview取消默认选中_C# WinForm 取消DataGridView的默认选中Cell 使其不反蓝的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表单的默认提交方式_对于PHP表单提交有
- 下一篇: 机器人测钢卷直径_酒钢碳钢冷轧钢卷自动焊