datagrid - Combox Box withing a Data Grid is not populated with data -
i doing when form loads up
datagridviewcomboboxcolumn combotextcol = new datagridviewcomboboxcolumn(); combotextcol.headertext = "some"; combotextcol.datasource = getemployees().select(e => new { name = e.lastname + " ," + e.firstname, id = e.employeeid }).tolist(); combotextcol.valuemember = "id"; combotextcol.displaymember = "name"; datagrid.columns.insert(0,combotextcol)
;
i tried datagrid.columns.add(combotextcol)
.
getemployees gives employee data see column not the data...??
firstly, code propose won't compile - missing capitalisation in 1 area , semi-colon @ end of last line (and not build issue, believe display correctly want white space after last name, not before). secondly, should amend so, there no apparent reason not display members. sure return value of getemployees
contains @ least on element?
consider following:
our employee type...
public class employee { public employee() { } public employee(int id, string firstname, string lastname) { employeeid = id; firstname = firstname; lastname = lastname; } public int employeeid { get; set; } public string firstname { get; set; } public string lastname { get; set; } }
and within load event of our form...
private void myform_load(object sender, eventargs e) { var employeea = new employee(28, "charlie", "brown"); var employeeb = new employee(42, "familiar", "stranger"); var employees = new list<employee>(); employees.add(employeea); employees.add(employeeb); var mydatagridview = new datagridview(); var mydatagridcomboboxcolumn = new datagridviewcomboboxcolumn(); mydatagridcomboboxcolumn.headertext = "employee"; mydatagridcomboboxcolumn.valuemember = "id"; mydatagridcomboboxcolumn.displaymember = "name"; mydatagridcomboboxcolumn.datasource = employees.select(employee => new { name = employee.lastname + ", " + employee.firstname, id = employee.employeeid }).tolist(); mydatagridview.columns.insert(0, mydatagridcomboboxcolumn); controls.add(mydatagridview); mydatagridview.dock = dockstyle.fill; }
the result absolute: expected elements appear in drop down box. give go, , manoeuvre way rid build errors maybe, seemingly, magically proceed point - didn't notice them? note sure how managed 'see' anything.
Comments
Post a Comment