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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox.Text

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
GB
i would like to set comboBox1.Text to "Enlarge To..." after it has been used. i tried writing comboBox1.Text = "Enlarge To..."; at the end of the selectIndexChanged method, but the comboBox changes is to comboBox1.selectedText straight after. How can i force it to keep my text?

____________________________________________________
If you like a post, show you care by giving it a <censored>.
 
1. Add a label to the combobox which will have a static text ("Enlarge to...") whenever the text of the combobox is changing or not.
2. Use LostFocus event and put back the initial text of the control after a selection is made and that will happen when another control takes the focus.
Also the Leave event is doing the same.
Code:
this.comboBox1.Text = "blabla";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
this.comboBox1.LostFocus += new System.EventHandler(this.comboBox1_SetInitialText);  

//..
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			textBox1.Text="Combobox selection was  " + comboBox1.Items[comboBox1.SelectedIndex];
                 // 	
		}
private void comboBox1_SetInitialText(object sender, System.EventArgs e)
		{
			comboBox1.Text="blabla";
		
		}
-obislavu
 
what do you mean bu 'add a label to the combo box'? are yo utalking about placing a label that covers the combobox up?

____________________________________________________
If you like a post, show you care by giving it a <censored>.
 
Just a Label at the left like you do for the TextBox to inform the user about the meaning of the text in this edit box or above the combobox.
-obislavu-
 
i don't understand how that label will help me. all i want to do is make sure my combobox always has the same text written on it, i don't need to tell the user what they selected.

the lostfocus event is no good because the combobox still has focus. i tried getting the combobox to loose focus, by passing focus to something else, but if you do it programmaticly, it doesn't trigger the lostfocus or leave events. i've also tried using the validated event, but to no avail.

____________________________________________________
If you like a post, show you care by giving it a <censored>.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top