2012-03-29 1 views
1

안녕하세요 프로그래머 실제로 DataGridvIew에 DataGridViewComboBoxCell이 있는데 CellContentClick 이벤트가 발생하면 조건이 true이면 DataGridViewComboBox 값을 변경해야합니다.CellContentClick 이벤트에서 DataGridviewComboBoxCell 값을 수동으로 선택하는 방법은 무엇입니까?

private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e) 
    { 
     int row = e.RowIndex; 
     int colo = e.ColumnIndex; 


     /*=============== To Show The Details =====================*/ 

     if (e.ColumnIndex == 4) 
     { 
      if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value)) 
      { 
       if (Type == "CUS") 
       { 
        Type = test.colType; 
        if (Type == "NO") 
        { 


         ComboBox combo = (ComboBox)sender; 
         combo.SelectedIndex = 0; 

        } 
       } 
    } 

을하지만, 콤보 상자에 DataGridView를 캐스팅하는 동안 오류를 제공합니다 : 내 코드는 다음과 같이 이동합니다.

도와주세요.

답변

1

안녕하세요!

나는 내 대답이 있고 수동으로 DataGridviewComboBoxCell을 선택합니다.

private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e) 
{ 
    int row = e.RowIndex; 
    int colo = e.ColumnIndex; 


    /*=============== To Show The Details =====================*/ 

    if (e.ColumnIndex == 4) 
    { 
     if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value)) 
     { 
      if (Type == "CUS") 
      { 
       Type = test.colType; 
       if (Type == "NO") 
       { 
        /*===== set the selected value of comboboxCellItems ==========*/ 

         gridviewholiday.Rows[e.RowIndex].Cells["colType"].Value="ALL" 



       } 
      } 
} 

마지막으로 내 문제가 해결되었습니다.

관련 문제