日期:2014-05-18 浏览次数:20872 次
private void Form2_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("aaa"); dt.Columns.Add("bbb"); dt.Rows.Add("0001","name1"); dt.Rows.Add("0002", "name1"); dt.Rows.Add("0003", "name1"); dt.Rows.Add("0004", "name1"); this.dataGridView1.DataSource = dt; this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.MultiSelect = false; } private void textBox1_TextChanged(object sender, EventArgs e) { foreach (DataGridViewRow dr in this.dataGridView1.Rows) { if (dr.Cells[0].Value == null) { continue; } if (dr.Cells[0].Value.ToString() == this.textBox1.Text) { dr.Selected = true; break; } } }
------解决方案--------------------