Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Having trouble with comboboxes?

Posted on 2014-03-24
8
Medium Priority
?
198 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 52

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

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 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