Found many articles online, but to no avail for the solution I am looking for.
My task: Add DataGridViewComboBoxColumn to datagridview, but each row should have different values in it's respective combobox.
This is my code,
dgv.Columns.Clear();
dgv.Rows.Clear();
dgv.Columns.Add("package", "Version");
foreach (DirectoryInfo item in (new DirectoryInfo("E:\\MyProjects")).GetDirectories())
{
dgv.Rows.Add(item.Name);
}
DataGridViewButtonColumn downloadColumn = new DataGridViewButtonColumn
{
HeaderText = "Download",
Name = "download",
Text = "Download",
UseColumnTextForButtonValue = true
};
dgv.Columns.Add(downloadColumn);
// Add Combobox column
DataGridViewComboBoxColumn books = new DataGridViewComboBoxColumn();
books.HeaderText = "Books";
books.Items.Add("Book1");
books.Items.Add("Book2");
dgv.Columns.Insert(1, books);
The drop downs are just empty. I have tried putting books.Items.Add(sub directories.Name) in a foreach loop for each row, then the combobox will not get any values at all. I am trying to show sub directories in the combo box. Not sure why it's not displaying the values (books.Items is still having the items I added, they are just not displaying).
What's driving me crazy is the same piece of code works on my home computer (Windows 10, Visual Studio 2013, .NET 4.5), but not on my office computer (Windows 7, Visual Studio 2012, .NET 4.5). Can someone please help!
I am getting this exception - DataGridView:System.ArgumentException: DataGridViewComboBoxCell value is not valid.To replace this default dialog please handle the DataError event.
Many thanks in advance!!!!