0

看来我在下面的代码中遗漏了一些东西:

 DataTable dt = new DataTable();
 DataColumn dt_col_project_id = new DataColumn("Project ID", typeof(Int32));
 DataColumn dt_col_activate = new DataColumn("On/Off", typeof(bool));
 DataColumn dt_col_nature = new DataColumn("Nature", typeof(String));
 DataColumn dt_col_name = new DataColumn("Circle List", typeof(String));
 DataColumn dt_col_keywords = new DataColumn("Keywords", typeof(String));
 DataGridViewComboBoxColumn dt_col_automation = new DataGridViewComboBoxColumn();

                //setup combobox                        
                dt_col_automation.HeaderText = "Automation";
                dt_col_automation.Name = "dgv_jobs_col_automation";
                    dt_col_automation.Items.AddRange(
                        "Once every 5 minutes",
                        "Once every 10 minutes",
                        "Once every 15 minutes",
                        "Once every 30 minutes",
                        "Once every hour",
                        "Once every 2 hours",
                        "Once every 3 hours",
                        "Once every 4 hours",
                        "Once every 5 hours",
                        "Once every 6 hours",
                        "Once every 7 hours",
                        "Once every 8 hours",
                        "Once every 9 hours",
                        "Once every 10 hours",
                        "Once every 11 hours",
                        "Once every 12 hours",
                        "1",
                        "2",
                        "3",
                        "4",
                        "5",
                        "6",
                        "7",
                        "8",
                        "9",
                        "10",
                        "11",
                        "12",
                        "13",
                        "14",
                        "15",
                        "16",
                        "17",
                        "18",
                        "19",
                        "20",
                        "21",
                        "22",
                        "23",
                        "24"
                    );



                    dt.Columns.Add(dt_col_project_id); // Create a string column dynamically
                    dt.Columns.Add(dt_col_activate); // Create a string column dynamically
                    dt.Columns.Add(dt_col_nature); // create an int column dyn
                    dt.Columns.Add(dt_col_name); // create a double column dyn
                    dt.Columns.Add(dt_col_keywords); // create a double column dyn
                    dt.Columns.Add(dt_col_automation); // create a double column dyn

因为它抛出了这些异常。我究竟做错了什么?

在此处输入图像描述

4

1 回答 1

2

您正在尝试将组合框列添加到绑定到 GridView 的 DataTable,而不是 Gridview 本身。DataGridViewComboBoxColumn 不继承自DataColumn,需要在GridView 中设置列​​,而不是在DataTable 上。

于 2012-01-04T19:11:42.933 回答