Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

System.FormatException: DataGridViewComboBoxCell value is not valid

$
0
0
I've read many other pages on this error, but none have helped me.

I'm getting the following exception when using a DataGridViewComboBoxColumn:

System.FormatException: DataGridViewComboBoxCell value is not valid

Using vs 2008 sp1


This code here works
    DataGridViewComboBoxColumn combCol1 = new DataGridViewComboBoxColumn();
    combCol1.HeaderText = "Application";
    combCol1.Name = "Application";
    combCol1.DataSource = ds.Application;
    combCol1.DisplayMember = ds.Application.NameColumn.ToString();
    combCol1.ValueMember = ds.Application.IdColumn.ToString();
    dgvMain.Columns.Add(combCol1);

And that fills my dropdowns with the options I want the user to be able to select

But now I hit a problem

I also want to display what is currently set in the database for that row, so I've done this:
int rowCount = dgvMain.Rows.Count - 1; // subtract 1 because DataGridView automatically adds a blank row at the bottomfor (int i = 0; i < rowCount; i++)
                {
                    dgvMain.Rows[i].Cells["Application"].Value = "test";
                }
This actually works, but when I run the program, it comes up with "System.FormatException: DataGridViewComboBoxCell value is not valid" many times.

And when I move my mouse over the dropdown, the message comes up many times again

What's going on? :(

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>