来源:http://social.msdn.microsoft.com ... -9cd5-b8d827182eeb/
- private void Form20_Load(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("c1");
- dt.Columns.Add("c2");
- dt.Columns.Add("c3");
- dt.Rows.Add("ava", "fbdfb", "dvsd");
- dt.Rows.Add("acsa", "dsd", "dcvsdv");
- dt.Rows.Add("avsdfger", "dfsd", "dvsd");
- dt.Rows.Add("bsdfsd", "bvsd", "ver");
- dt.Rows.Add("befesd", "vev", "bgf");
- dt.Rows.Add("cfbdf", "nhgn", "asda");
- this.dataGridView1.DataSource = dt.DefaultView;
- this.dataGridView1.MultiSelect = false;
- this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- if (this.textBox1.Text != "")
- {
- for (int j = 0; j < this.dataGridView1.RowCount - 1; j++)
- {
- if (this.dataGridView1[0, j].Value != null)
- {
- if (this.dataGridView1[0, j].Value.ToString().StartsWith(
- this.textBox1.Text))
- {
- this.dataGridView1.CurrentCell = this.dataGridView1[0, j];
- this.dataGridView1.Rows[j].Selected = true;
- }
- }
- }
- }
- }
复制代码 |