Click here to Skip to main content
15,897,968 members

The following exception occured in the DataGridView:

Mangukiya Shailesh asked:

Open original thread
The following exception occured in the DataGridView:
System.ArgumentException: DataGridViewComboBoxCell Value is not valid.
To replace this default dialog please handle the DataError Event.


i have a datagridview and in datagridview two fill combobox from database but when i select combobox value in second row the above following error occured...in c# windows application....
and plz ans send me my email address..

my email is msv.svm@gmail.com

so plz help me...

private void sample_Load(object sender, EventArgs e)
{


SqlCommand cmd = new SqlCommand("Select CatID, CatName from CategoryMaster", cnn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(dt);

Column1.DataSource = dt;
Column1.DisplayMember = "CatName";
Column1.ValueMember = "CatID";

}

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{

string catID = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

SqlCommand cmd1 = new SqlCommand(@"SELECT ProdID, ProdName FROM ProductMaster WHERE CatID ='" + catID + "' ", cnn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
dt1.Clear();
da1.Fill(dt1);

dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
Column2.DataSource = dt1;
Column2.DisplayMember = "ProdName";
Column2.ValueMember = "ProdID";

}
}
Tags: DataGridView

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900