private List<Control> GetControls(TableBasedDropDownField field, Size canvasSize) { string displayMember = field.TextColumnName.Trim(); string valueMember; if (field is DDLFieldOfCodes) { valueMember = field.CodeColumnName.Trim(); ((DDLFieldOfCodes)field).ControlFactory = this; } else if (field is DDListField) { valueMember = field.CodeColumnName.Trim(); ((DDListField)field).ControlFactory = this; } else { valueMember = field.TextColumnName.Trim(); } ComboBox comboBox = new Epi.Windows.Enter.Controls.LegalValuesComboBox(); SetControlProperties(comboBox, field, canvasSize); if (field is DDListField) { comboBox.DropDownStyle = ComboBoxStyle.Simple; } else { comboBox.DropDownStyle = ComboBoxStyle.DropDown; } comboBox.Sorted = field.ShouldSort; if (!string.IsNullOrEmpty(displayMember)) { comboBox.DisplayMember = null; comboBox.ValueMember = null; if (cachedListValues == null) { cachedListValues = new Dictionary<string, DataTable>(); } DataTable displayTable; if (cachedListValues.ContainsKey(displayMember + "," + field.SourceTableName)) { displayTable = cachedListValues[displayMember + "," + field.SourceTableName]; } else { displayTable = field.GetDisplayTable("", "", displayMember); cachedListValues.Add(displayMember + "," + field.SourceTableName, displayTable); } if (displayTable != null) { comboBox.BeginUpdate(); comboBox.Items.AddRange(displayTable.AsEnumerable().Select(row => row.Field<string>("Item") ?? string.Empty).ToArray()); comboBox.EndUpdate(); if (displayTable.Rows.Count > 0) { if (field.CurrentRecordValueObject == null || string.IsNullOrEmpty(field.CurrentRecordValueString)) { comboBox.SelectedIndex = -1; } else { comboBox.SelectedItem = field.CurrentRecordValueString; } } } } Label prompt = GetPrompt(comboBox, field, canvasSize); List<Control> controls = new List<Control>(); controls.Add(prompt); controls.Add(comboBox); field.Control = comboBox; if (!fieldControls.ContainsKey(field)) { fieldControls.Add(field, controls); } else { fieldControls.Remove(field); fieldControls.Add(field, controls); } return controls; }
private List<Control> GetControls(YesNoField field, Size canvasSize) { ComboBox comboBox = new Epi.Windows.Enter.Controls.LegalValuesComboBox();//ComboBox(); SetControlProperties(comboBox, field, canvasSize); comboBox.DropDownStyle = ComboBoxStyle.DropDown;//ComboBoxStyle.DropDownList; comboBox.AutoCompleteSource = AutoCompleteSource.ListItems; comboBox.FlatStyle = FlatStyle.Standard; DataTable dt = new DataTable(); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("value", typeof(int)); DataRow dr; dr = dt.NewRow(); dr["name"] = config.Settings.RepresentationOfYes; dr["value"] = Constants.YES; dt.Rows.Add(dr); dr = dt.NewRow(); dr["name"] = config.Settings.RepresentationOfNo; dr["value"] = Constants.NO; dt.Rows.Add(dr); comboBox.ValueMember = "value"; comboBox.DisplayMember = "name"; comboBox.DataSource = dt; // Create Prompt Label prompt = GetPrompt(comboBox, field, canvasSize); List<Control> controls = new List<Control>(); controls.Add(prompt); controls.Add(comboBox); if (fieldControls.ContainsKey(field)) { fieldControls[field] = controls; } else { fieldControls.Add(field, controls); } if (field.CurrentRecordValueObject == null || string.IsNullOrEmpty(field.CurrentRecordValueString)) { comboBox.SelectedIndex = -1; } else { comboBox.SelectedItem = field.CurrentRecordValueString; } return controls; }