TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Stephen Anderson
NA
16
2.7k
Populate datagridview column combobox datasource
Jun 13 2018 1:46 PM
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();
// How do I add combobox columns?
dgvTime.Controls.OfType<DataGridViewComboBoxColumn>().ElementAt(iProjectNo).DataSource = lstProjectNumbers;
dgvTime.Controls.OfType<DataGridViewComboBoxColumn>().ElementAt(iActivity).DataSource = lstActivity;
this
.timeDataTableAdapter1.Fill(
this
.timeDataSet.TimeData);
Thank you.
Reply
Answers (
4
)
Display selected row data to the text box of other window.
How to Read Xml in DataTable or DataSet