public static void fillComboWithUsers(ComboBox cmb, int defaultId) { UsersDA da = new UsersDA(); String cond = "ACTIVE=1"; UsersEntity entity = da.load(cond); var dataSource = new List <ComboBoxItem>(); cmb.DataSource = null; cmb.Items.Clear(); BasicInfoUtil.AddUnKnown(dataSource); for (int i = 0; i < entity.Tables[entity.FilledTableName].Rows.Count; i++) { string name = entity.get(i, UsersEntity.FIELD_NAME) + " " + entity.get(i, UsersEntity.FIELD_FAMILY) + " ( " + entity.get(i, UsersEntity.FIELD_USERNAME) + " ) "; string id = entity.get(i, UsersEntity.FIELD_ID).ToString(); dataSource.Add(new ComboBoxItem(name, id)); } cmb.DataSource = dataSource; cmb.DisplayMember = "Text"; cmb.ValueMember = "Value"; for (int i = 0; i < cmb.Items.Count; i++) { if (((ComboBoxItem)cmb.Items[i]).Value.Equals(defaultId.ToString())) { cmb.SelectedIndex = i; break; } } }
public static void fillComboBox(ComboBox cmb, int defaultItem) { cmb.Items.Clear(); ChequeBL bl = new ChequeBL(); ChequeEntity entity = bl.get(); var dataSource = new List <ComboBoxItem>(); BasicInfoUtil.AddUnKnown(dataSource); for (int i = 0; i < entity.Tables[entity.FilledTableName].Rows.Count; i++) { string id = entity.Tables[entity.FilledTableName].Rows[i][ChequeEntity.FIELD_ID].ToString(); string desc = entity.Tables[entity.FilledTableName].Rows[i][ChequeEntity.FIELD_BANK_ID].ToString(); dataSource.Add(new ComboBoxItem(desc, id, "")); } cmb.DataSource = dataSource; cmb.DisplayMember = "Text"; cmb.ValueMember = "Value"; for (int i = 0; i < cmb.Items.Count; i++) { if (((ComboBoxItem)cmb.Items[i]).Value.Equals(defaultItem.ToString())) { cmb.SelectedIndex = i; break; } } }
private void fillUserRefferenceCombo(int defaultValue) { UserTreeBL userTreeBL = new UserTreeBL(); int loggineduserid = int.Parse(UsersBS.loginedUser.get(UsersEntity.FIELD_ID).ToString()); UserTreeEntity entity = userTreeBL.getUserAllAccessPath(loggineduserid); cmbReferenceUserId.DataSource = null; cmbReferenceUserId.Items.Clear(); var dataSource = new List <ComboBoxItem>(); BasicInfoUtil.AddUnKnown(dataSource); for (int i = 0; i < entity.Tables[entity.FilledTableName].Rows.Count; i++) { string name = entity.get(i, UserTreeEntity.VIEW_FIELD_USER_NAME).ToString(); string treeid = entity.get(i, UserTreeEntity.FIELD_ID).ToString(); string userid = entity.get(i, UserTreeEntity.FIELD_USER_ID).ToString(); dataSource.Add(new ComboBoxItem(name, treeid, userid)); } cmbReferenceUserId.DataSource = dataSource; cmbReferenceUserId.DisplayMember = "Text"; cmbReferenceUserId.ValueMember = "Value"; for (int i = 0; i < cmbReferenceUserId.Items.Count; i++) { string c = ((ComboBoxItem)cmbReferenceUserId.Items[i]).CustomData; if (c != null && c.Equals(defaultValue.ToString())) { cmbReferenceUserId.SelectedIndex = i; break; } } }