2016-05-30 90 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; 
       } 
      }