Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Having trouble with comboboxes?

Posted on 2014-03-24
8
Medium Priority
?
211 Views
Last Modified: 2014-03-24
This is bugging me. My problem is that I'm obviously not sure what events to use for a ComboBox. I know the SelectedIndexChanged event is the default event but it seems to fire whenever the value in the ComboBox changes. I understand that but are there any events that you can use that will allow you to select a value from the DropDownList and not have any other events fire. This is becoming a mountain instead of a molehill!!!!!
0
Comment
Question by:BlakeMcKenna
  • 4
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39950492
Hi,

Aren't you lokoking for

ComboBox.SelectionChangeCommitted

Regards
0
 

Author Comment

by:BlakeMcKenna
ID: 39950543
What property do I check for then to validate the selection? Once I've selected an item, I then do an edit check and I've tried SelectedItem, SelectedText, Text and they're all blank...
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 39950774
SelectedIndexChanged is useful if you want to trigger something right after a new selection.

But for validation, for all controls, Validating is usually the best choice. It triggers only when the user gets out of the control, so it will not fire while the user is interacting with the control.

As for what property to use to check the validation, it depends on what the validation is and how the ComboBox was filled.

The Text property is OK if you want to validate against what is displayed in the ComboBox. It will be blank only if the user left the selection to a blank entry.

SelectedText is usually not what you want. If the user selected only a few letters in the displayed information, you will get only these letters.

SelectedItem depends on what you used to fill the ComboBox. If it is filled only with strings, it should work. But if you filled the ComboBox with a collection, DataTable or the like, you need to cast SelectedItem to the underlying type in order to be able to retrieve the properties of the selected item.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:BlakeMcKenna
ID: 39951534
James,

This information was very helpful. One more question though. What event and property would be the best to use as soon as a value is selected from the DropDownList?
0
 
LVL 40
ID: 39951639
If the values are unique (the same value does not appear twice), then SelectedIndexChanged is the best one to use.

As for the property to use to read the value, it depends on the type of objects that are used to fill the list and what you want to retrieve in that object. What type of object do you use to fill the list: strings, collection, other?
0
 

Author Comment

by:BlakeMcKenna
ID: 39951717
James,

I fill the comboboxes with a string value via a dataset. The DisplayMember contains a string and the ValueMember contains an integer.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 39951760
Assuming that you assigned the whole DataSet to the DataSource property of yourCombo, then you can use any of the followings, depending on your needs.

yourCombo.Text will give you your string

CInt(yourCombo.SelectedValue) will give your your integer

DirectCast(yourCombo.SelectedItem,DataRow) will give you access to any of the fields in the DataRow that was selected. Use it as you would a DataRow.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39951790
Thanks James...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question