2016-11-19 101 views

回答

2

您需要设置CUrrentCell第一,随后通过true为参数,将当前单元格在编辑模式下,选择所有单元格的内容调用BeginEdit。例如:

this.dataGridView1.CurrentCell = this.dataGridView1.Rows[2].Cells[0]; 
this.dataGridView1.BeginEdit(true); 

注:例如,如果你要根据一定的价值发现在DataGridView第一个单元格,然后选择单元格,并开始编辑,你可以使用这样的代码:

var cell = dataGridView1.Rows.Cast<DataGridViewRow>() 
       .SelectMany(x => x.Cells.Cast<DataGridViewCell>()) 
       .Where(x => string.Format("{0}", x.FormattedValue) == textBox1.Text) 
       .FirstOrDefault(); 
if (cell != null) 
{ 
    this.dataGridView1.CurrentCell = cell; 
    this.dataGridView1.BeginEdit(true); 
} 
+0

对于例如,如果您想根据某个值在“DataGridView”中查找第一个单元格并选择该单元格并开始编辑,请阅读** Note **部分。对于更复杂的情况(例如创建查找窗口),您可能需要使用不同的机制来进行搜索。 –

相关问题