2011-08-11 2 views
1

DataGridView 셀을 두 번 클릭하면 어떻게 한 번 폼을 열 수 있습니까?DataGridView를 두 번 클릭하여 양식을 두 번 이상 열 수 없도록하려면 어떻게합니까?

private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    //string queryString = "SELECT id, thename, address,fax,mobile,email,website,notes FROM movie"; 
    int currentRow = int.Parse(e.RowIndex.ToString()); 
    try 
    { 
     string movieIDString = dataGridView1[0, currentRow].Value.ToString(); 
     movieIDInt = int.Parse(movieIDString); 
    } 
    catch (Exception ex) { } 
    // edit button 
    if (e.RowIndex != -1) 
    { 
     string id = dataGridView1[0, currentRow].Value.ToString(); 
     string thename = dataGridView1[1, currentRow].Value.ToString(); 
     string address = dataGridView1[2, currentRow].Value.ToString(); 
     string fax = dataGridView1[3, currentRow].Value.ToString(); 
     string mobile = dataGridView1[4, currentRow].Value.ToString(); 
     string email = dataGridView1[5, currentRow].Value.ToString(); 
     string website = dataGridView1[6, currentRow].Value.ToString(); 
     string notes = dataGridView1[7, currentRow].Value.ToString(); 

     Form4 f4 = new Form4(); 

     f4.id = movieIDInt; 
     f4.thename = thename; 
     f4.address = address; 
     f4.fax = fax; 
     f4.mobile = mobile; 
     f4.email = email; 
     f4.website = website; 
     f4.notes = notes; 


     f4.Show(); 
    } 
} 

이 코드는 내가 열 경우 DoubleClick은 form.cs에서 글로벌 변수로 다시

+0

Click 이벤트 처리기 또는 DoubleClick 이벤트 처리기 (또는 CellClick 또는 CellDoubleClick ...)에 게시 한 코드가 있습니까? – digEmAll

+0

dataGridView1_CellMouseDoubleClick – amer

답변

1

클래스 필드에 열린 양식을 유지하십시오.
예 : 코드 대신 다음과 같은 메서드를 호출하십시오.

Form4 f4 = null; // class field 

    // call this method when cellMouseDoubleClick is triggered 
    private void OpenForm4IfNotOpened() 
    { 
     if (f4 == null || f4.IsDisposed) 
     { 
      f4 = new Form4(); 

      f4.id = movieIDInt; 
      f4.thename = thename; 
      f4.address = address; 
      f4.fax = fax; 
      f4.mobile = mobile; 
      f4.email = email; 
      f4.website = website; 
      f4.notes = notes; 
      f4.Show(); 
     } 
     else 
     { 
      f4.BringToFront(); 
     } 
    } 
+0

digEmAll thanks :) – amer

+0

@amer : 안녕하세요. 어쨌든 StackOverflow가 작동하기 때문에 올바른 대답이라고 생각하는 대답 (여기뿐만 아니라 previos 질문에서도)을 받아 들여야합니다 ;-) [(링크 : 대답을 수락하는 방법)] (http : // meta. stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – digEmAll

1

선언이 그것을 열리지 않습니다 원하는 폼을 내가있는 DataGridView를 클릭 할 때마다 열립니다

bool isopened = false; 

는 가장 좋은 방법은 가변 F4 클래스 L하는 것이다

if (isopened == false) 
      { 
       FormInitialSettings(); 
       Form4 f4 = new Form4(); 

       f4.id = movieIDInt; 
       f4.thename = thename; 
       f4.address = address; 
       f4.fax = fax; 
       f4.mobile = mobile; 
       f4.email = email; 
       f4.website = website; 
       f4.notes = notes; 
       isopened = true; 
       f4.Show(); 
      } 
0

isopened 변수 확인 evel varuiable 및 Form4 f4 = new Form4(); 줄은 한 번만 실행 한 다음 f4.Show(); 줄 앞에 표시해야 양식이 다시 표시되기 전에 이미 표시되는지 확인할 수 있습니다.

관련 문제