Pergunta

It seems I am missing something from my code below:

 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

Because it's throwing these exceptions. What am I doing wrong?

enter image description here

Foi útil?

Solução

You are trying to add a combobox column to the DataTable that is bound to the GridView, not the Gridview itself. DataGridViewComboBoxColumn does not inherit from DataColumn, you need to set up the columns in the GridView, not on the DataTable.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top