添加一个DataGridVeiw, textBox
进行数据绑定
textBox1.DataBindings.Add("Text", ds, "SysParams.KeyName");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "SysParams";   //ds是Dataset SysParams是表名好了 现在的问题是 我需要根据指定条件查询记录 如果有记录
dataGridView的指针 要移到查询出来的记录(是移动 不是只显示一条)
textBox1 也显示对应数据请问要怎么处理?? 

解决方案 »

  1.   

    既然是绑定了,
    直接对数据源根据条件 find即可跳到该记录。
      

  2.   

    查询出来你不绑定到dgv就行了,你如果绑定了(就只显示你查询的记录),然后让查出来的记录高亮,同时把查询出来的记录付给textbox。
      

  3.   

        private void button1_Click(object sender, EventArgs e)
            {
                string name =TextBox1.Text;//设置的查询条件,如果多条件,在后面继续添加
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (item.Selected == true)  //设置如果条件不符合时  取消选中行
                    {
                        item.Selected = false;
                    }
                    if (name != "")
                    {
                        if (item.Cells["name"].Value.ToString() == name)
                        {
                            dataGridView1.CurrentCell = item.Cells[0]; //设置光标(第一行的箭头)是否为选中行
                                textbox1.text=item.Cells[0].Value.ToString();//要显示那个字段的信息就设置那个
                            return;
                        }
                    }
                }
            }