Combo Box Error - DataGridViewComboBoxCell value is not valid
-
I am trying to get the Combo Box working so that i can get the drop-down boxes available for the database columns to be placed in the DataGridView. But i am getting the following error when the data displays in the DataGridView The following exception occurred in the DataGridView: System.ArgumentException: DataGridViewComboBoxCell value is not valid. To replace this default dialog please handle the DataError event Background: The way i am selecting the 'Column Type' is through the Designer. So i can choose the DataGridViewTextBoxColumn or DataGridViewComboBoxColumn The dataGridView is hooked up to a bindingSource and I have my bindingSource wired to a List Object. There is a dataTime picker control on the form, which is used to pull the data. When i choose the DataGridViewTextBoxColumn, the data displays perfect. But when i change the 'Column Type' to DataGridViewComboBoxColumn, running the form gives the error repeatedly and as i click on each error, one row of data displays and so on. Does anyone have a suggestion?
-
I am trying to get the Combo Box working so that i can get the drop-down boxes available for the database columns to be placed in the DataGridView. But i am getting the following error when the data displays in the DataGridView The following exception occurred in the DataGridView: System.ArgumentException: DataGridViewComboBoxCell value is not valid. To replace this default dialog please handle the DataError event Background: The way i am selecting the 'Column Type' is through the Designer. So i can choose the DataGridViewTextBoxColumn or DataGridViewComboBoxColumn The dataGridView is hooked up to a bindingSource and I have my bindingSource wired to a List Object. There is a dataTime picker control on the form, which is used to pull the data. When i choose the DataGridViewTextBoxColumn, the data displays perfect. But when i change the 'Column Type' to DataGridViewComboBoxColumn, running the form gives the error repeatedly and as i click on each error, one row of data displays and so on. Does anyone have a suggestion?
This error occured when datagrid column value not match with combobox colloection items.this error can be handle on datagrid dataerror events. void view_DataError(object sender, DataGridViewDataErrorEventArgs e) { if (e.Exception.Message == "DataGridViewComboBoxCell value is not valid.") { object value = view.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; if (!((DataGridViewComboBoxColumn)view.Columns[e.ColumnIndex]).Items.Contains(value)) { ((DataGridViewComboBoxColumn)view.Columns[e.ColumnIndex]).Items.Add(value); e.ThrowException = false; } } } Jitender Parnami
-
I am trying to get the Combo Box working so that i can get the drop-down boxes available for the database columns to be placed in the DataGridView. But i am getting the following error when the data displays in the DataGridView The following exception occurred in the DataGridView: System.ArgumentException: DataGridViewComboBoxCell value is not valid. To replace this default dialog please handle the DataError event Background: The way i am selecting the 'Column Type' is through the Designer. So i can choose the DataGridViewTextBoxColumn or DataGridViewComboBoxColumn The dataGridView is hooked up to a bindingSource and I have my bindingSource wired to a List Object. There is a dataTime picker control on the form, which is used to pull the data. When i choose the DataGridViewTextBoxColumn, the data displays perfect. But when i change the 'Column Type' to DataGridViewComboBoxColumn, running the form gives the error repeatedly and as i click on each error, one row of data displays and so on. Does anyone have a suggestion?
In C#.net You should handle data error event of the datagridview private void grdGuestServiceDetail_DataError(object sender, DataGridViewDataErrorEventArgs e) { if(e.Context== (DataGridViewDataErrorContexts.Formatting) || e.Context==(DataGridViewDataErrorContexts.PreferredSize)) { e.ThrowException = false; } } and In VB.net Private Sub DataGridView_DataError(ByVal sender As Object, ByVal e As DataGridViewDataErrorEventArgs) If (e.Context _ = (DataGridViewDataErrorContexts.Formatting Or DataGridViewDataErrorContexts.PreferredSize)) Then e.ThrowException = false End If