[英]textbox textchange event to click the checkbox in datagridview
I have a textbox and a datagridview with checkbox.我有一个文本框和一个带有复选框的数据网格视图。 The excel import into datagridview. excel 导入 datagridview。 I add the checkbox into datagridview.我将复选框添加到 datagridview 中。 I want to input the number into textbox and this number will match the column in datagridview.我想将数字输入到文本框中,这个数字将与 datagridview 中的列匹配。 please help me!请帮我!
private void TextBox2_TextChanged(object sender, EventArgs e)
{
}
private void TextBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
button4.Focus();
Button4_Click(sender,e);
textBox2.Focus();
}
}
private void Button4_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[3].Value.ToString() == textBox2.Text)
{
row.Cells[0].Value = ((CheckBox)dataGridView1.Controls.Find("DataGridViewCheckBoxCell", true)[0]).Checked;
}
}
}
private void Form9_Load(object sender, EventArgs e)
{
TextBox textBox = new TextBox();
textBox.TextChanged += new EventHandler(TextBox2_TextChanged);
}
Set this property when setting up your DataGridView在设置 DataGridView 时设置此属性
dataGridView1.Columns[0].ValueType = typeof(CheckState);
And then in your Event Handler set the cell using this然后在您的事件处理程序中使用此设置单元格
if (row.Cells[3].Value.ToString() == textBox2.Text)
{
row.Cells[0].Value = CheckState.Checked;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.