none
DataGridView Default Error Dialog --------------------------- The following exception occurred in the DataGridView: System.ArgumentException: DataGridViewComboBoxCell value is not valid.

    Question

  • Here is the code
     string tbname = comboBox1.SelectedItem.ToString();
               OleDbConnection con = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=N:\\DB\\SampleData.mdb;");
                    conn.Open();
                dataGridView1.Rows.Clear();
                OleDbConnection con = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=N:\\DB\\SampleData.mdb;");
                con.Open();
      DataTable dt = conn.GetSchema("Tables");
    string tbname = textBox1.Text;
                            dataGridView1.Rows.Clear();
                OleDbDataAdapter ad = new OleDbDataAdapter("Select * from" + " " + tbname + " ", con);
                DataTable dt = new DataTable();
                ad.Fill(dt);
                int j = 0;
              
                for (int i = 0; i < dt.Columns.Count; i++) //Getting Columns Name present in the table
                {
                    dataGridView1.Rows.Insert(i, "");
                    dataGridView1.Rows.Insert(i, "");
                                cname[i] = dt1.Columns[i].ColumnName;
                                 cname1[j] =Convert.ToString(dt.Columns[i].DataType);
     dataGridView1.Rows[i].Cells[0].Value = cname[i];
     dataGridView1.Rows[i].Cells["DATA_TYPE"].Value = cname1[j];//here i want populate data types in combobox //Here i'm getting error like above what i asked
                                j++;
                }
               // comboBox4.SelectedIndex = 0;  
                con.Close();
    Monday, January 09, 2012 10:46 AM

All replies

  • You are giving a value in ComboBoxCell which is not existing in Parent Table.

    I thing the value is Zero therefore the error is being occurred.

    Update the parent Table and Grid Table records. 

    Sunday, October 27, 2013 1:14 PM