Hello:
I would like the correct C# syntax to populate datagridview column comboboxes. Each column will look at a query (Entity Framework 6), converted to a list, and would make those values the correct ones to choose from. There should also be a blank for a default.
Currently, I have this code.
- DataTable dt_Employee = timeDataSet.Tables["Employee"];
- DataTable dt_TimeData = timeDataSet.Tables["TimeData"];
- DataTable dt_Activity = timeDataSet.Tables["Activity"];
- DataTable dt_Jobs = timeDataSet.Tables["Jobs"];
- var qryProjectNumbers = from a in dt_Jobs.AsEnumerable()
- orderby a.Field<String>("ProjectNumber")
- where (a.Field<String>("ProjectNumber") != null)
- select a.Field<String>("ProjectNumber");
- var lstProjectNumbers = qryProjectNumbers.Distinct().ToList();
- var qryActivity = from a in dt_Jobs.AsEnumerable()
- orderby a.Field<String>("Activity")
- where (a.Field<String>("Activity") != null)
- select a.Field<String>("Activity");
- var lstActivity = qryActivity.Distinct().ToList();
-
- dgvTime.Controls.OfType<DataGridViewComboBoxColumn>().ElementAt(iProjectNo).DataSource = lstProjectNumbers;
- dgvTime.Controls.OfType<DataGridViewComboBoxColumn>().ElementAt(iActivity).DataSource = lstActivity;
- this.timeDataTableAdapter1.Fill(this.timeDataSet.TimeData);
Thank you.