Using AddRange to populate comboBox with data stored in a Dictionary
Posted on 2016-09-13
Good morning experts,
This is my first time trying to use the comboBox AddRange method in C#.
I have data retrieved from a table in SqlServer database and placed in Dictionary, the key is of integer type and the value is of type string.
Next comes the problem of placing the pair (key and value) int a comboBox. I tried several things but none worked.
Below is the code which is placed on the Form_Load event where the comboBox reside:
private void FrmADDNewCleaningJob_Load(object sender, EventArgs e)
RetrieveAllUnits getUnits = default(RetrieveAllUnits);
getUnits = new RetrieveAllUnits();
if (getUnits.Dict.Count > 0)
foreach (var pair in getUnits.Dict)
// code to fill the comboBox
MessageBox.Show("We have a problem!");