2012-03-29 21 views
1

嗨程序員, 其實我在DataGridvIew DataGridViewComboBoxCell,我需要更改DataGridViewComboBox值,如果條件爲真時CellContentClick事件被觸發。 我的代碼是這樣的:如何在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" 



       } 
      } 
} 

最後我的問題解決了。

相關問題