双击dataGridView1中任意的单元格触发

时间:2023-01-22 19:27:28
 
 private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //获取行首的单元格双击事件,并以此值作为传参对象
            string  CellValue = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value .ToString ();
           //MessageBox.Show(CellValue);
            

            SqlConnection con = new SqlConnection(DRIVER);					
            con.Open();
            string strsql = "select id,sid,name,tell,address,shangpinname,shangpinprice,nums,BuyTime from T_customor where id="+CellValue;
            SqlCommand cmd = new SqlCommand(strsql, con);
            SqlDataReader rd = cmd.ExecuteReader();						
           // int id = rd.GetOrdinal("title");						
            while (rd.Read())											
            {
                this.txt_username.Text = rd["name"].ToString();
                this.txt_tell2.Text = rd["tell"].ToString();
                this.txt_address.Text = rd["address"].ToString();
                this.txt_shangpinname.Text = rd["shangpinname"].ToString();
                this.txt_id.Text = rd["sid"].ToString();
                this.txt_nums.Text = rd["nums"].ToString();
                this.txt_price.Text = rd["shangpinprice"].ToString();
                this .label5 .Text =rd ["id"].ToString ();

            }

            tabControl1.SelectTab(tabPage1);  //使tabPage1显示 


        }