Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox Leave event

Status
Not open for further replies.

Katy44

Technical User
Joined
Dec 12, 2003
Messages
723
Location
GB
I have a combobox with a leave event:

Code:
private void comboBox2_Leave(object sender, System.EventArgs e)
		{
			MessageBox.Show("Text is "+comboBox2.Text);
		}

It always seems to be one step behind where I think it should be - when I first look at the combonbox it has its default value. I then type in some text ("Hello"), and move away. It displays the first text, not "Hello" as I want it to. DOes anyone know why?
 
You should add the text you typed in as an object in the Itms collection if it doesn't exist.
Code:
private void comboBox2_Leave(object sender, System.EventArgs e)
{
   	if (comboBox2.Items.Contains(comboBox2.Text))
		return;
	comboBox2.Items.Add(comboBox2.Text);
}
obislavu
 
I don't actually want to add it if it doesn't exist - I want the nice functionality where they can start typing it in and it will find the records, but then I only want them to end up with an entry in the list. However checking the 'comboBox2.Items.Contains' could be exactly what I am looking for - thank you.
 
This is my situation:
I really want a drop down list, but I also want the nice functionality where you can type a word and it takes you to that entry in the list, in the same way as the DropDown. I am happy for an entry to be typed in, and then for it to be validated. I haven't found a good description of a combobox, but this is the way I understand it:

A comboBox's Value is the value you want to use within your code (most likely some sort of key)
The DisplayMember is what you want displaying to the user when they drop down the box, and is linked in a 1-1 relationship with Value
The Text is what is typed into the comboBox, and bears no relation at all to the above two.
What are the Items?

What I want is, while they are typing, it to take them to the DisplayMember that they are beginning to type. I want a Leave event to check that that actually is one of the DisplayMembers and display a message if not.
This doesn't seem to be working. First, I'll ask if anyone knows a much simpler way to do what I want to do? If not, I'll explain what is going wrong.
 
obislavu thanks for your help by the way, I'm not sure what is in 'Items', but it didn't seem to work as I hoped it would. I'm hoping that I am making this all much more difficult than it actually needs to be. Do you have any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top