2

I want to populate the value in datagridview cell based on selection changed event of combo box which is residing inside the datagridview.

In the below screenshot I want to populate value in Area column based on selection change event of combobox data grid view.

enter image description here

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Parag Pathari
  • 281
  • 2
  • 5
  • 19
  • Try the code of this question [DataGridViewComboBoxCell value is invalid with binded DataGridViewComboBoxCell](http://stackoverflow.com/questions/28854881/datagridviewcomboboxcell-valuevalue-is-invalid-with-binded-datagridviewcomboboxc/28874060#28874060) – user4340666 May 30 '16 at 08:41
  • Use [`CellValueChanged`](https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged(v=vs.110).aspx) event. – Reza Aghaei May 30 '16 at 09:54

1 Answers1

1

Try This

  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;
          }
        }

If U creating DataGridViewComboBoxCell object

  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;
              }
            }
Tanmay Nehete
  • 2,138
  • 4
  • 31
  • 42