[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10556
  • Last Modified:

DataGridView containing DataGridViewComboBoxColumn VS 2008 C# Windows App

I am attempting to add a DataGridViewComboBoxColumn to an existing DataGridView control. I am having difficulty populating the combobox with dropdown values, and I am not able to view them when I select the combobox dropdown when the grid has finished loading. I have searched for a small working example where combobox values are being added programatically but have had no luck. Could someone explain why the dropdown values are not populating or are not viewable in the dropdown list?

I have included my test code:
DataTable dtBook = new DataTable();
//Create Columns in DataGridView
dtBook.Columns.Add("bookid", typeof(int));
dtBook.Columns.Add("bookname", typeof(string));
dtBook.Columns.Add("startTime", typeof(DateTime));
dtBook.Columns.Add("endTime", typeof(DateTime));
//Create Rows in DataGridView
for (int i = 0; i < 10; i++)
   DataRow dr = dtBook.NewRow();
   dr[0] = i;
   dr[1] = "book" + i.ToString();
   dr[2] = new DateTime(2007, 1, 1);
   dr[3] = DateTime.Now;
//Add Rows to DataGridView
dataGridView1.DataSource = dtBook;
//Create DataGridView ComboBox Column
DataGridViewComboBoxColumn colStatus = new DataGridViewComboBoxColumn();
colStatus.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
//Specify the list of choices in the combo box
colStatus.Items.AddRange("New", "Used");
//Sort the combo box contents alphabetically
colStatus.Sorted = true;
//Disable sorting for the column
colStatus.SortMode = DataGridViewColumnSortMode.NotSortable;
colStatus.HeaderText = "Condition";
colStatus.Name = "Condition";
colStatus.ReadOnly = false;

Open in new window

1 Solution
ImInOrlandoAuthor Commented:
My previous grid had read only set to true AND the Selection Mode was set to Full Row Select. I caught the Selection Mode issue but I don't think I would have even looked at the Read Only property for the grid until I eventually dropped a new DataGridView control and sorted through the differences. Hope this might help those like myself in the future! =]

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now