Question : System.FormatException:DatagridviewComboboxcell value is not valid

Hi,

I have a datagridviewcombobox column. The combobox values are binded with database values.
This combobox is editable.I used the following code.

private void dataGridView1_EditingControlShowing(object sender,          DataGridViewEditingControlShowingEventArgs e)
        {          
            ComboBox combo = e.Control as ComboBox;
           
            if (combo != null)
            {
                combo.AutoCompleteMode = AutoCompleteMode.Suggest;
                combo.AutoCompleteSource = AutoCompleteSource.ListItems;
                combo.DropDownStyle = ComboBoxStyle.DropDown;
                if (dataGridView1.CurrentRow.Index == dataGridView1.Rows.Count - 1)
                {
                    combo.SelectedIndex = -1;                  
                }
               
                if (combo != null && CountSubscribers(combo, "SELECTEDINDEXCHANGED") == 0)
                {
                    combo.BindingContext = new BindingContext();


                    combo.DropDownStyle = ComboBoxStyle.DropDown;
                    combo.SelectedIndex = -1;
                 
                    combo.Text = "";
                   
                    combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectionChange);
                    combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectionChange);
                    combo.DropDown -= new EventHandler(combo_dropdown);
                    combo.DropDown += new EventHandler(combo_dropdown);
                    combo.LostFocus -= new EventHandler(ComboBox_TextChanged);
                    combo.LostFocus += new EventHandler(ComboBox_TextChanged);
                    }
                }                
            }
        }
Whenever user selects an item form combobox and its focus is lost,then other cell values of datagridview will be filled .we have editable columns in gridview. But problem is, when user selects an item and press "tab" then " System.FormatException: DatagridviewComboboxCell value is not valid " exception raises.I have uploaded some screenshots.Please check it and let me know the solution.  
 
Editable combobox
305305
 
 
user selects an item and press tab:error
305306
 

Answer : System.FormatException:DatagridviewComboboxcell value is not valid

Random Solutions  
 
programming4us programming4us