|
|||||||
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Lively Member
Join Date: Apr 05
Location: Orlando
Posts: 104
![]() |
[2005] Adding and removing an item from Combo box causes odd behavior.
Hello community..
Situation: I have a combobox with three items in the collection. I have a condition when selected that removes an invalid option from the combobox so the user cant select it. Issue: When the condition reverses and the option is a valid choise, when selcted form the drop down it does not stay in the "combo box"(ill explain better) When you pick a item it shows in the combo box's control area, now when i selct the item i removed from the combo box list.it does not appear in the controls drawn area. here is my code that does the event. Code:
If (cboSqlSearchCriteria.SelectedIndex = 0 Or cboSqlSearchCriteria.SelectedIndex = 5 Or cboSqlSearchCriteria.SelectedIndex = 7) Then
Try
cboSqlCondition.Items.RemoveAt(2)
cboSqlCondition.Items.Add("Like (%text%)")
cboSqlCondition.Update()
Catch ex As Exception
cboSqlCondition.Items.Add("Like (%text%)")
End Try
Else
Try
cboSqlCondition.Items.RemoveAt(2)
Catch ex As Exception
'no event
End Try
End If
|
|
|
|
|
|
#2 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,022
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [2005] Adding and removing an item from Combo box causes odd behavior.
If you mean when you add a value to the combobox, it isn't the current selected item, that is just because you need to set it as the current selected item.
When you call the .add method, it returns an integer. the integer is the index in the list where the item was added. So you could do code like this: cboSqlCondition.SelectedIndex = cboSqlCondition.Items.Add("whatever") keep in mind setting the selectedindex or the text property of the combobox will make the selectedindexchanged event fire again.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com -=Matt=- |
|
|
|
|
|
#3 |
|
Lively Member
Join Date: Apr 05
Location: Orlando
Posts: 104
![]() |
Re: [2005] Adding and removing an item from Combo box causes odd behavior.
im sorry.. Selecting the item is not the issue.
Ill explain step by step... 1. App is running.. 2. Combobox1 contains 3 items in its list when control has focus and list displayed. 3. Select condition on separate control that removes item at index 2 on combobox1. 4. Return to combobox1 and now 2 items appear as they should. When selelecting an item form the list it moves to the Displayed feild of the combobox when one moves focus away form combobox1 as it should be. 5. Now upon selecting the control that re adds the last item(index item 2) upon a condition it does so. 6. Return once more to combobox1 and see the 3 items once more in the list. BUT... When selecting the item from the list i just added it does not display in the Control like the other two items , the display value remains blank, even when i test to see what index it is showing it says index 2 as selected value but nothing appears int he combobox. If i select any of the other two non removed and added items they show correctly and display fine. here is a attemp to show what i see... Combobox---->________(empty, no selection yet) List items-----itemindex 0 List items-----itemindex 1 List items-----itemindex 2 I select itemindex 1 Combobox------> Item1 (displayed) I select itemindex 2 combobox------> ______ (nothing displayed, even tho item appears in list.) Hope that helps. EDIT: My code above trys to check for item 2 if it exsists and remove it or add it back under the correct condition. Last edited by smilbuta; Apr 20th, 2007 at 04:20 PM. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|