2011-10-06 3 views
0

이 DataGridView가 있으며 파일을 클릭 할 때마다 ... openFileDialog를 열 때마다 나타납니다. 지금까지 체결했지만 작동하지 않습니다OpenFileDialog가 표시되지 않습니다.

enter image description here

.

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) 
{ 
    string bbb = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); 
    if (bbb == "Browse From File...") 
    { 
     openFileDialog2.ShowDialog(); 
    } 

이 아무것도뿐만 아니라 시도 :

if (e.ColumnIndex.Equals = "Browse From File...") 
if (dataGridView1.SelectedCells = "Browse From File...") 
if ((string)dataGridView1.SelectedCells[0].Value == "Browse From File...") 
if (dataGridView1.Rows[1].Cells["Browse From File..."].Value.ToString() == "Browse From File...") 
      { 
       //openFileDialog2.ShowDialog(); 
      } 
+3

이벤트가 발생하면 디버그를 시도 했습니까? –

+0

첫 번째 예제에서 디버그 할 때 bbb는 무엇이 동일합니까? 점점 ((DataGridViewCell) 보낸 사람) 시도 했습니까? 값? – Timbo

+0

디버그하고 다음 줄에 bbbin의 값을 알려주십시오. if (bbb == "Browse From File ...") –

답변

0

하나의 솔루션은 데이터 그리드에서 컨트롤이 표시되는 이벤트 (EditingControlsShowing)를 잡아 콤보 상자 인 selectionchanged 처리기를 추가하는 것입니다. 이 같은

뭔가 : 그리드에 이벤트 처리기를 추가하기 위해

private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) 
    { 
     if (e.Control is ComboBox) 
     { 
      ComboBox cellComboBox = (ComboBox)e.Control; 
      if (cellComboBox != null) 
      { 
       cellComboBox.SelectedIndexChanged += new EventHandler(cellComboBox_SelectedIndexChanged); 
      } 
     } 
    } 

    void cellComboBox_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     DataGridViewComboBoxEditingControl comboBox = sender as DataGridViewComboBoxEditingControl; 
     if (comboBox != null) 
     { 
      if (String.Compare(comboBox.Text, "Browse From File...") == 0) 
      { 
       openFileDialog.ShowDialog(); 
      } 
     } 
    } 

편집

: 양식 및 그리드에 마우스 오른쪽 버튼으로 클릭에 대한 디자인보기로 이동합니다. 컨텍스트 메뉴에서 속성을 클릭하십시오. 등록 정보 창에서 이벤트 단추 (번개 이미지)를 클릭하고 EditingControlShowing 항목을 검색하십시오. 빈 공간을 두 번 클릭하여 이벤트 처리기를 추가하십시오. 뒤에있는 페이지 코드에서 * dataGridView1_EditingControlShowing *과 비슷한 빈 메서드가 표시됩니다.이 메서드는 위의 메서드에서 코드를 복사하여 붙여 넣습니다. 그 옆에 동일한 소스 파일의 두 번째 메서드 cellComboBox_SelectedIndexChanged에 복사/붙여 넣기도 있습니다.

+0

** 작동하지 않습니다. **이 방법으로는 작동하지 않습니다. 나는 중단 점을 토글했고 그들은 프로그램을 멈추지 않았다. –

+0

방금 ​​테스트 해본 결과 저에게 적합합니다. 데이터 격자에 이벤트 처리기를 추가 했습니까? this.dataGridView.EditingControlShowing + = new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler (this.dataGridView_EditingControlShowing); –

+0

어디에 넣어야합니까? 버튼 방식으로 추가했는데 오류가 있음을 보여주었습니다. –

0

무엇입니까?

if (bbb.equals("Browse From File...")) 
관련 문제