日期:2014-05-18  浏览次数:20872 次

各位大侠,这样子代码为什么在textbox输入数值后,datagridview中没选中相应的行数据,没反应????
各位大侠,这样子代码为什么在textbox输入数值后,datagridview中没选中相应的行数据,没反应????

private void textBox4_TextChanged(object sender, EventArgs e)
  {
  foreach (DataGridViewRow each in dataGridView1.Rows)
  {
  if (textBox4.Text == this.dataGridView1.CurrentRow.Cells["序号"].Value.ToString())
  {
  this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

  }
  }

  }

------解决方案--------------------
给你整了个
C# code

 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;
                }
            }
        }

------解决方案--------------------
探讨

给你整了个
C# code

private void Form2_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("aaa");
dt.Columns.Add("bbb");
……