有点BUG
以下修正
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex.Equals(this.dataGridView1.Columns["Company"].Index))
{ //this.dataGridView1.Controls.Clear(); 此处的清除控件应该放在CellLeave事件中处理
//
Button btn = new Button();
btn.Text = "...";
btn.Font = new Font("Arial", 7);
btn.Visible = true;
btn.Width = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Height;
btn.Height = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Height;
this.dataGridView1.Controls.Add(btn);
btn.Location = new System.Drawing.Point((this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true)
.Right - btn.Width), this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Y);
btn.Click += new EventHandler(btn_Click);
} }
void btn_Click(object sender, EventArgs e)
{
Form f = new Form();
f.ShowDialog(this.dataGridView1);
} private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView1.Controls.Clear(); //清除集合中控件
}
以下修正
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex.Equals(this.dataGridView1.Columns["Company"].Index))
{ //this.dataGridView1.Controls.Clear(); 此处的清除控件应该放在CellLeave事件中处理
//
Button btn = new Button();
btn.Text = "...";
btn.Font = new Font("Arial", 7);
btn.Visible = true;
btn.Width = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Height;
btn.Height = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Height;
this.dataGridView1.Controls.Add(btn);
btn.Location = new System.Drawing.Point((this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true)
.Right - btn.Width), this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Y);
btn.Click += new EventHandler(btn_Click);
} }
void btn_Click(object sender, EventArgs e)
{
Form f = new Form();
f.ShowDialog(this.dataGridView1);
} private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView1.Controls.Clear(); //清除集合中控件
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货