2012-10-12 6 views
1

이것이 가능한지 확실하지 않지만 DataGridView 셀 안에있는 단추의 인스턴스를 가져 오려고합니다. (C# .net 및 windows 폼 작업)DataGridView 셀 안에있는 버튼의 인스턴스를 가져 오는 방법은 무엇입니까?

이 이유는 버튼 근처에 컨트롤이있는 패널을 팝업하고 싶기 때문입니다. 그래서 그 위치가 필요합니다. (이것이 가능한가?).

나는 CellClicked 이벤트 처리기에서 버튼 클릭을 처리 해요 :

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
     Int32 id = (Int32)dataGridView1[0, e.RowIndex].Value; 
     if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["NewDate"].Index) 
     { 
      if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["Delete"].Index) return; 
      else 
      { 

      } 
     } 
     else 
     { 
      //Button button - the button I'm trying to get 
      panel2.Location=new Point(button.Location.X,button.Location.Y); 

     } 

    } 
+0

답을 확인 했습니까? –

답변

1

당신은 버튼 만 클릭 한 셀의 사각형을받을 필요가 없습니다. 코드 확인 :

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
     Int32 id = (Int32)dataGridView1[0, e.RowIndex].Value; 
     if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["NewDate"].Index) 
     { 
      if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["Delete"].Index) return; 
      else 
      { 

      } 
     } 
     else 
     { 
      Rectangle rect = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); 
      panel2.Location=new Point(rect.X,rect.Y); 

     } 

    } 
+0

나는 그것을 시험해 볼 수 없다. –

관련 문제