1. 程式人生 > >點選DataGridView裡面的某一個單元格的事件

點選DataGridView裡面的某一個單元格的事件

 private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                this.dataGridView2.Controls.Clear();
                btnDetail.Bounds = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                btnDetail.Visible = true;
                btnDetail.Text = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
                btnDetail.Click += new EventHandler(btnDetail_Click);
                this.dataGridView1.Controls.Add(btnDetail);
            }
            else
            {
                btnDetail.Visible = false;
            }
        }