Do not use on any
shared computer
August 21, 2008 03:17pm pdt
 
[x]
Attachment Details

VB.NET 2.0 ComboBox events - Detecting Not In List

Tags: combobox
I am building my first Windows Forms application in VB.NET 2.0. Up to now I have used Access as a front end to talk to SQL Server or some other database.

I am using the new ComboBox AutoComplete functionality. DropDpwnStyle is set to DropDown.

When a user leaves a ComboBox control I want to determine if they have chosen a value from the list, typed in a value that is not on the list, or chosen the default value of 'Please select a Company/Division/Contact/etc.'

Depending on their choice, the following should happen:

1.  If they have chosen the default value of 'Please select a Company/Division/Contact/etc.' a message box prompts them to select a valid value and the focus returns to the control.

2. If they have typed in a value that is not on the list a message box asks "Do you want to create a new Company/etc.?".
    -  If they answer Yes they are directed to a new form to add the item. When the item is added the form closes and they are back on the original form. The ComboBox data source is refreshed to include the new value which is now selected.
    -  If they answer No the focus returns to the control.

3.  If they have chosen a non-default value from the list other ComboBoxes may be filled based on the choice and the focus passes to the next control.

Which event(s) do I use to handle each scenario?

I tried LostFocus. It seems that the SelectedIndex event has not fired yet so I only see the "old" value.

The same is true for Leave.

The SelectedIndexChanged event doesn't seem to fire at all in the case of #2.

SelectedIndexChanged and LostFocus also seem to fire when the ComboBox.DataSource is being bound to the DataTable. I don't want to respond to any of these.

For some reason the LostFocus event ot the next control in the tab order fires before the user actually sees that this control has the focus.

I could use Leave, get the ComboBox.Text property, compare that to the datasource, determine which of the three cases had occurred and respond accordingly.

That works, but it seems like I am overlooking something that built in to handle this.

Since this is my first app in .NET 2.0 I want to learn properly.

Thanks!

John
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: JohnDesautels
Solution Provided By: Priest04
Participating Experts: 2
Solution Grade: A
Views: 244
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by Priest04

Rank: Guru

Expert Comment by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by JohnDesautels
Author Comment by JohnDesautels:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Priest04

Rank: Guru

Expert Comment by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by JohnDesautels
Author Comment by JohnDesautels:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Priest04

Rank: Guru

Expert Comment by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by JohnDesautels
Author Comment by JohnDesautels:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Priest04

Rank: Guru

Accepted Solution by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by JohnDesautels
Author Comment by JohnDesautels:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Priest04

Rank: Guru

Expert Comment by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by JohnDesautels
Author Comment by JohnDesautels:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Priest04

Rank: Guru

Expert Comment by Priest04:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Open Discussion
Open Discussion
 
Comment by OrmetExperts
Have you found problems where the user selects an item from the list, then decides to enter his own new data in the combo box?  #4 below seems to be the worse case.
I have been testing this to try to develop a sequence of events and values to account for the following:
1. User typed letters and selcted from "suggest" list. Did not open list.
2. User selected from the drop down list and moved out of field.
3. User did not open drop down and just typed in NEW data.
4. User opened drop down list, selected an item, (changed his/her mind), typed in new data, moved out of field.

Is there some property that I'm missing besides SelectionChangeCommitted to help reset the previously selected values (ie: selectedindex, selectedvalue) so that the new entered data has accurate values?

I'm looking for some sort of reset method to address item #4 above.

thanks in advance for any comments or suggestions.





 
 
Comment by JohnDesautels
OrmetExperts,

This question has been closed.

I suggest you ask a related question (http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/newQuestionWizardRelated.jsp?qid=22606600) if you want experts to assist you.

Otherwise, no one will know you need help.

John
 
 
20080723-EE-VQP-34