2012-05-18 2 views
1

I 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를 사용하지 마십시오. 그러나 이것이 도움이되기를 바랍니다.

관련 문제