GrammatonCleric
Well-Known Member
I'm a SQL / BI Developer by profession, so please bear with me.
I fill a WinForms ComboBox with values from a table in my database using an async Task<Dictionary<int, string>>. This happens in my constructor. I have a switch..case statement on the SelectedIndexChanged EventHandler to fill a DataSet when an item in the ComboBox is selected. I will eventually change this to a generic List object to consume less memory etc.
The problem I have is...if I insert a new value into the table that populates the ComboBox, the indexes change as the items in the ComboBox are ordered alphabetically and the switch..case statement isn't viable anymore because the indexes are different each new item added to the table / ComboBox.
Is there a way to get around this?
I'm considering using the 'key' in the Dictionary as the 'value' are the items shown in the ComboBox, but the ComboBox SelectedIndex property is zero-based. I'm not too sure if the Dictionary 'key' is zero-based as well, but I'm not too sure how to do this.
Any guidance from a C# pro would be super!
I fill a WinForms ComboBox with values from a table in my database using an async Task<Dictionary<int, string>>. This happens in my constructor. I have a switch..case statement on the SelectedIndexChanged EventHandler to fill a DataSet when an item in the ComboBox is selected. I will eventually change this to a generic List object to consume less memory etc.
The problem I have is...if I insert a new value into the table that populates the ComboBox, the indexes change as the items in the ComboBox are ordered alphabetically and the switch..case statement isn't viable anymore because the indexes are different each new item added to the table / ComboBox.
Is there a way to get around this?
I'm considering using the 'key' in the Dictionary as the 'value' are the items shown in the ComboBox, but the ComboBox SelectedIndex property is zero-based. I'm not too sure if the Dictionary 'key' is zero-based as well, but I'm not too sure how to do this.
Any guidance from a C# pro would be super!