DataGridViewComboBox value is not valid?

cougar picture cougar · Jun 11, 2012 · Viewed 7.4k times · Source

I keep getting an error that states DataGridViewComboBox value is not valid. It seems like it is also in an endless loop: I will click ok and it will continuously keep popping up. I am running a program with a windows form application written in C# and .NET. Does anyone know how to fix this error?

Here is some portions of my code:

// authorityTypeDataGridViewTextBoxColumn
// 
this.authorityTypeDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
this.authorityTypeDataGridViewTextBoxColumn.DataPropertyName = "AuthorityType";
this.authorityTypeDataGridViewTextBoxColumn.DataSource = this.AuthorityTypeBindingSource;
this.authorityTypeDataGridViewTextBoxColumn.DisplayMember = "Description";
this.authorityTypeDataGridViewTextBoxColumn.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox;
this.authorityTypeDataGridViewTextBoxColumn.Frozen = true;
this.authorityTypeDataGridViewTextBoxColumn.HeaderText = "AuthorityType";
this.authorityTypeDataGridViewTextBoxColumn.MaxDropDownItems = 100;
this.authorityTypeDataGridViewTextBoxColumn.Name = "authorityTypeDataGridViewTextBoxColumn";
this.authorityTypeDataGridViewTextBoxColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.authorityTypeDataGridViewTextBoxColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.authorityTypeDataGridViewTextBoxColumn.ValueMember = "Value";
this.authorityTypeDataGridViewTextBoxColumn.Width = 121;
// 
// AuthorityTypeBindingSource
// 
this.AuthorityTypeBindingSource.DataMember = "AuthorityType";
this.AuthorityTypeBindingSource.DataSource = this.lookUpDataSet;

Does anyone have any suggestions?

Here is the Handler:

private void TaskSummaryGrid_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
    MessageBox.Show(this, e.Exception.Message);
    e.Cancel = true;
}

Answer

HKhan picture HKhan · Aug 29, 2013

yeah the solution is to make datagridviewcombobox cell value the same you are getting in the code behind.

if i want to show typeof(int) value , i must set property of the datagridviewcombobox cell like:

this.ComboboxCellcolumnName.ValueType = typeof(int); 

the value type that you got(e.g int) should be the same you want to show in the combobox cell (int).