Solved

Having trouble with comboboxes?

Posted on 2014-03-24
8
162 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 48

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 500 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now