Solved

Having trouble with comboboxes?

Posted on 2014-03-24
8
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 51

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 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