>I want the Items combo to be blank when I select a different category. Unfortunately, it behaves this way - temporarily shows the item correspoding to the previously selected index and then goes blank. Any way to prevent wrong item to display?I see in another post that you already figured this one out, changing
this.cboItems.SelectedIndex = 0; //Start from the empty item
-to-
this.cboItems.SelectedIndex = -1; //Start from the empty item
was what I was going to suggest. Just thought I'd reiterate in response to the post that asked the question, in case there are interested lurkers.
~~Bonnie
>>I think you're missing a this._inventoryList.Clear() before the foreach loop. Try also resetting cboItems.DataSource to null before the foreach loop.
>>
>>>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.
>
>There is a little problem with this code I'm not sure how to avoid:
>
>
> private void RefreshItemsCombo()
> {
> string SelectedItem = this.cboCategories.Text.Trim();
> this._inventoryList.Clear();
> this.cboItems.DataSource = null;
>
> if (SelectedItem != "")
> {
> this._inventoryEntries = _inventoryBiz.GetInventoryDictionaryByCategory(SelectedItem);
> _inventoryList.Add("");
>
> foreach (KeyValuePair<string, string> kvp in this._inventoryEntries)
> {
> this._inventoryList.Add(kvp.Key);
> }
> this.cboItems.Enabled = true;
> this.cboItems.DataSource = this._inventoryList;
> this.cboItems.SelectedIndex = 0; //Start from the empty item
> }
> else
> this.cboItems.Enabled = false;
>
> }
>
>
>I want the Items combo to be blank when I select a different category. Unfortunately, it behaves this way - temporarily shows the item correspoding to the previously selected index and then goes blank. Any way to prevent wrong item to display?
>
>Thanks in advance.