I am working on C#.net windows application. i am filling combobox on my winform by using follows.
cmbEMPType.DataSource = objEntityManager.EmployeeTypes(); cmbEMPType.DisplayMember = "EMPTypeName"; cmbEMPType.ValueMember = "EMPTypeId"; where objEntityManager.EmployeeTypes(); in the manager method that gets the List from Linq to sql server. this is working fine.
but as i select the item form combo box, and clicked the button then in the button click event i am getting cmbEMPType.SelectedValue as EmpType return type rather than its Id. why should this? I don't want to create one more EmpType object. need simple selected value. also can not keep faith with SelectedIndex. it may varies for item each time.
**Edited** public List<EMPType> EmployeeTypes() { List<EMPType> EMPTypeList = null; try { if (CommonDataObject.dataContext.EMPAllTypes.Any()) { EMPTypeList = CommonDataObject.dataContext.EMPAllTypes.ToList(); } return EMPTypeList; } catch { return EMPTypeList; } } Edited
private void btnSave_Click(object sender, EventArgs e) { iEMPTypeId = cmbEMPType.SelectedValue; } here I must get inte. but asking of create the EMPType object.