2016-05-30 91 views
2

我想根據駐留在datagridview內的組合框選擇更改的事件填充datagridview單元格中的值。Combobox datagridview選擇更改datagridview其他單元格中的填充值

在下面的截圖我想基於組合框的數據網格視圖的選擇更改事件區列填充值。

enter image description here

+0

嘗試這一問題的代碼[的DataGridViewComboBoxCell值與綁定的DataGridViewComboBoxCell無效](HTTP:/ /stackoverflow.com/questions/28854881/datagridviewcomboboxcell-valuevalue-is-invalid-with-binded-d atagridviewcomboboxc/28874060#28874060) – user4340666

+0

使用['CellValueChanged'](https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged(V = vs.110)的.aspx)事件。 –

回答

1

嘗試這個

Private DG_CellValueChanged(Object sender , DataGridViewCellEventArgs e) 
    { 
    if(e.RowIndex.equls(-1)) 
     { 
     return; 
     } 
    if(e.ColumnIndex.Equls(0)) 
     { if(e.RowIndex.equls(-1)) 
      { 
      return; 
      } 
     if(e.ColumnIndex.Equls(0)) 
      { 
      string sVal=//Your Calculation 
      DG.Rows[e.RowIndex].Cell[1].value=sVal; 
      } 
     } 

。如果U創建的DataGridViewComboBoxCell對象

Private DG_CellValueChanged(Object sender , DataGridViewCellEventArgs e) 
      { 
      if(e.RowIndex.equls(-1)) 
       { 
       return; 
       } 
      if(e.ColumnIndex.Equls(0)) 
       { 
       string sVal=//Your Calculation 
       DG.Rows[e.RowIndex].Cell[1].value=sVal; 
       } 
      }