Solved

Having trouble with comboboxes?

Posted on 2014-03-24
8
176 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 50

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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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