1

我有以下函数响应 DataGridView 中的 ColumnHeaderMouseDoubleClick 事件:

void grid_ColumnHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
    TextBox t = new TextBox();
    //make the new textbox the same size as the header to cover it up until text is entered
    t.Width = ((DataGridView)sender).CurrentCell.ContentBounds.Width;
    t.Height = ((DataGridView)sender).CurrentCell.ContentBounds.Height;
    t.Dock = DockStyle.Fill;
    t.Visible = true;
    t.BringToFront();
    t.Text = "TEST";
    Controls.Add(t);
}

所有这些代码都发生在一个扩展 Panel 的类中,并将 DataGridView 添加到面板的控件中。当我双击标题并在此处理程序上放置断点时,将调用处理程序,但我在任何地方都看不到文本框。有人知道我做错了什么吗?

4

1 回答 1

0

我首先将文本框设为类字段(在事件触发器之外声明它,这样它就不会超出范围)。可能还必须设置文本框的坐标:)。这台机器上没有 VS 来试试这个,但我希望这会有所帮助。

于 2012-05-18T18:10:52.377 回答