Reputation: 2796
I am developing the windows based application in which i need to bind the comboboxcolumns inside the datagridview with values from the [Attendance_type] table. And the datasource of this datagridview will be from [Employees table].
I am currently doing this using this code.
dgvEmployee.Columns.Clear();
dgvEmployee.AutoGenerateColumns = false;
DataGridViewTextBoxColumn branchcolumn = new DataGridViewTextBoxColumn();
branchcolumn.DataPropertyName = "Name";
branchcolumn.HeaderText = "Employee Name";
branchcolumn.Name = "Name";
branchcolumn.Width = 200;
dgvEmployee.Columns.Add(branchcolumn);
var metaattend = from Metaatt in dataDC.Metaattend
where Metaatt.Status == true
orderby Metaatt.Metaname
select Metaatt;
List<Metaattend> obj_ma = new List<Metaattend>();
obj_ma = metaattend.ToList();
var Empvar = from Emp in dataDC.Employees
join dept in dataDC.Dept on Emp.Deptid equals dept.Id
join branch in dataDC.Branch on Emp.Branchid equals branch.Id
where Emp.Status == true & Emp.Name.Contains(txtbranch.Text)
& (Emp.Deptid == Convert.ToInt64(cmbDept.SelectedValue) | cmbDept.SelectedValue.ToString() == "0")
& (Emp.Branchid == Convert.ToInt64(cmbBranch.SelectedValue) | cmbBranch.SelectedValue.ToString() == "0")
orderby Emp.Name
select new { Emp.Id, Emp.Name };
DataTable dt_employee = new DataTable();
using (clsGeneral obj_gen = new clsGeneral())
{
dt_employee = obj_gen.LINQToDataTable(Empvar);
}
dgvEmployee.DataSource = dt_employee;
string[] datemonth = cmbMonth.Text.Split('-');
int i = DateTime.DaysInMonth(Convert.ToInt32(datemonth[1]), GetMonthNo(datemonth[0]));
for (int j = 0; j < i; j++)
{
DataGridViewComboBoxColumn daycomboColumn = new DataGridViewComboBoxColumn();
daycomboColumn.HeaderText = (j + 1).ToString();
daycomboColumn.Width = 50;
daycomboColumn.DataSource = obj_ma;
daycomboColumn.DisplayMember = "Metaname";
daycomboColumn.ValueMember = "Id";
dgvEmployee.Columns.Add(daycomboColumn);
}
Using this the code is executed successfully, but the form does not shows me any record in the column for combobox inside the datagridview.
This is the view of my form, when i click on the comboboxes then also it does not shows me anything.
I have seen many post about this but none was helpfull for me. As that all shows me the same thing that i have done.
Please help be with about where i have done the mistake.
Thanks
Upvotes: 1
Views: 1331
Reputation: 2796
Enable Row Editing property for the datagridview was set to false. so it was not showing the Data inside the combobox.
Upvotes: 2