DataGridViewComboBoxCell Binding - “value is not valid”

前端 未结 10 744
臣服心动
臣服心动 2020-11-30 09:45

I\'m trying to bind separate ComboBox cells within a DataGridView to a custom class, and keep getting an error

DataGridViewComboBoxCell value is not v

10条回答
  •  有刺的猬
    2020-11-30 10:17

    I am having the same problem. After populating my ComboBox column in the (unbouod) DataGrid, I solved my problem by setting the ValueMember property of the DataGridViewComboBoxColumn Apparently, just relying on the ToString() property of the objects in the ComboBox is not enough.

    Actual code:

    /// 
    /// Populate the dataGridSplitVolumes data grid with all existing qualifications for the plan.
    /// 
    /// 
    private void PopulateDataGridSplitVolumes(Bonus_Group bonus)
    {
      try
      {
        List qualifications = Qualification.Load(this.groupBonus.PlanID, this.ConnectionString);
        foreach (Qualification qual in qualifications)
        {
          DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)this.dataGridSplitVolumes.Columns[0];
          col.Items.Add(qual);                    
        }
        SplitVolumeGrid_QualificationColumn.ValueMember = "Name";
      }
      catch (Exception ex)
      {
    #if DEBUG
        System.Diagnostics.Debugger.Break();
    #endif
        throw ex;
      }
    }//PopulateDataGridSplitVolumes     
    

提交回复
热议问题