To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Apr 20th, 2007, 01:40 PM   #1
smilbuta
Lively Member
 
smilbuta's Avatar
 
Join Date: Apr 05
Location: Orlando
Posts: 104
smilbuta is an unknown quantity at this point (<10)
[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
Any advice apreciated, will give more info if requested... Thanx!
smilbuta is offline   Reply With Quote
Old Apr 20th, 2007, 02:28 PM   #2
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,482
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
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 2010/.NET 2.0 through 4.0 * 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! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

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=-
kleinma is offline   Reply With Quote
Old Apr 20th, 2007, 03:16 PM   #3
smilbuta
Lively Member
 
smilbuta's Avatar
 
Join Date: Apr 05
Location: Orlando
Posts: 104
smilbuta is an unknown quantity at this point (<10)
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 03:20 PM.
smilbuta is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:30 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.