// Sets up the list that will be added to the combobox input public ComboBoxInputData(string idAttribute, string nameAttribute, string queryTables, string queryCondition, string sortAttributes, bool addNullInput = false) { SelectedIds = new List <int>(); OptionsListIds = addNullInput ? new List <int> { 0 } : new List <int>(); OptionsListNames = addNullInput ? new List <string> { "None" } : new List <string>(); using (var conn = AccessDB.Connect()) { conn.Open(); string select = "SELECT " + idAttribute + ", " + nameAttribute + " FROM " + queryTables; using (var reader = SQLDB.Read(conn, select + " WHERE " + queryCondition + " ORDER BY " + sortAttributes + " ASC;")) { while (reader.Read()) { OptionsListIds.Add(int.Parse(reader[idAttribute].ToString())); OptionsListNames.Add(reader[nameAttribute].ToString()); } } conn.Close(); } }
public int FindIndex(object targetData) { if (targetData == null || targetData.ToString() == "") { return(0); } int targetIndex = OptionsListIds.FindIndex(a => a.ToString() == targetData.ToString()); return(targetIndex < 0 ? 0 : targetIndex); }