2012-05-18 41 views
1

我有以下的功能,使其能夠應對一個DataGridView的ColumnHeaderMouseDoubleClick事件:放置在標題欄頂部的文本框在一個DataGridView

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); 
} 

所有這些代碼是一個擴展面板類的內部發生並將DataGridView添加到面板的控件中。當我雙擊頭並在這個處理程序上放置一個斷點時,處理程序被調用,但是我沒有在任何地方看到這個文本框。有人知道我在做什麼錯嗎?

回答

0

我首先將文本框設置爲一個類字段(在事件觸發器之外聲明它,以便在它結束時不超出範圍)。可能必須爲textBox設置座標:)。這臺機器上沒有VS來試用,但我希望這會有所幫助。

相關問題