private void comNameComboBox_SelectedIndexChanged(object sender, EventArgs e) { try { ComboBox cmb = (ComboBox)sender; int selectedIndex = cmb.SelectedIndex; int selectedValue = (int)cmb.SelectedValue; string comId = String.Format("{0}", selectedValue); stockinModel.ComId = Convert.ToInt32(comId); _stockInManagers.CatWiseItems(stockinModel); catNameComboBox.DataSource = _stockInManagers.ComWiseCat(stockinModel); catNameComboBox.DisplayMember = "Name"; catNameComboBox.ValueMember = "Id"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }