The main reason for your problem is that the โSelectโ value does not exist in your list of combo box values. You will need to either add this to the data source for the column, or to the data source for the individual list cells (using the edit control for that cell).
The following is a few explanations when setting the value of the selected item that I'm going to leave, as you may find it useful.
There are two main ways to set the value of a DataGridViewComboBoxColumn. You either use data binding or set the value directly.
It looks like you are trying to install directly, so I will explain this first and then below. I will complete the answer with data binding.
Taking the following contrived example:
public partial class Form1 : Form { public Form1() { InitializeComponent(); BindingList<User> users = new BindingList<User> { new User() { UserName = "Fred", userid = 2 } }; IList<MyValue> values = new List<MyValue> { new MyValue{id = 1, name="Fred"}, new MyValue{id = 2, name="Tom"}}; dataGridView1.DataSource = users; DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn(); col.DataSource = values; col.DisplayMember = "name"; col.DataPropertyName = "userid"; col.ValueMember = "id"; dataGridView1.Columns.Add(col); } } public class MyValue { public int id { get; set; } public string name { get; set; } } public class User { public string UserName { get; set; } public int userid {get;set;} }
In this example, I set the ValueMember property to "id", which refers to the identifier of the property names in the list to which the ComboBox is bound.
So, all I need to do is the following (where I am sure my row and cell indices are correct - you have to write code to check this):
dataGridView1.Rows[0].Cells[2].Value = 1;
Now in my example, this works because my ValueMember my id property set, which is an integer, if id was a string property instead, I would need to set the value as follows:
dataGridView1.Rows[0].Cells[2].Value = "1";
(actually just tried this and it is manipulated with implicit casting)
And, of course, I would like to make sure that there really was a value of "1" on my list.
The above lines are the direct cause of your error - your list, which supplies the values โโin the combo box, does not contain the value "Select".
To set a value using data binding, you need to tell ComboBoxColumn that it is required in the DataGridView data source.
My setup is DataPropertyName in ComboBoxColumn on the property name of the class that the DataGridView is associated with.