Sylvain,
The first time the selected item is 'Select Category', but then it could be any category. However, it seems like I can only select category once to get the Items displayed correctly - every time I select anyhing else it remains the same - it should clear the Items combo value and allow me to select items for the selected category - this part I can not get to work as hard as I already tried.
I'll move the handler to the private method - good point.
>Isn't SelectedItem == "Select Category" only true the first time around?
>
>BTW, I see two design flaw in this code:
>1) Hard coded "Select Category". What if the text change later? Internationalized?
>2) No code shoud be in event handlers. cboCategories_SelectedIndexChanged should call a private method.
>
>>I have the simple problem - two related comboboxes. One to select Category and another to select items by Category. I can not get it to work - it seems to only work the first time.
>>
>>Do you see where is my problem in this code?
private void cboCategories_SelectedIndexChanged(object sender, EventArgs e)
>> {
>> string SelectedItem = this.cboCategories.Text.Trim();
>> if (SelectedItem != "Select Category")
>> {
>> this._inventoryEntries = _inventoryBiz.GetInventoryDictionaryByCategory(SelectedItem);
>>
>> foreach (KeyValuePair<string, string> kvp in this._inventoryEntries)
>> {
>> this._inventoryList.Add(kvp.Key);
>> }
>> this.cboItems.Enabled = true;
>> this.cboItems.DataSource = this._inventoryList;
>> }
>> else
>> this.cboItems.Enabled = false;
>> }
If it's not broken, fix it until it is.
My Blog