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

Need exhaustive breakdown of combobox behavior

Status
Not open for further replies.

keyser456

IS-IT--Management
Nov 21, 2003
73
US
Ok. I'm throwing my hands up in frustration with the behavior of comboboxes. Trying to determine what events fire when and under what circumstances is near impossible.

For example:
When does SelectionChangeComitted fire? How does the enter key correspond to this event? Tab key? How does the state of the list (DroppedDown = true or false) affect this event? When you clear text in the box and hit enter, half the time it fires, half the time it doesn't. I can't reproduce certain behaviors all the time and there are just too many variables for me to even start to figure out specific rules. Throw into that the Invalidated, SelectedItemChanged, SelectedValueChanged, and ValueMemberChanged events and you've got a royal cluster. Can anyone point me to a helpful link? I have several books, but none are specific enough. I'd like it to cover all the intricacies of comboboxes. Thanks!
 
I hate to disturb the chirping crickets in this thread but...

Basically I'm trying to get the enter key to work exactly like the tab key. After several hours of experimenting this is what I've come up with:

//this is in the custom combo box class
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((int)e.KeyChar == 13)
{
e.Handled = true;
this.FindForm().Validate();
this.FindForm().SelectNextControl(this, true, true, true, true);
}
else
{
base.OnKeyPress (e);
}
}

The containing form's Validate method mentions it "validates the last invalidated control and it's ancestors up through, but not including, the current control." It doesn't sound like it should be validating the current combobox but it does work. The interesting behavior is that the above code "validates" the control twice. Once when you run the containing form's Validate method and once before moving focus to the next control. However, if I don't use the form's Validate method before using SelectNextControl I have no way of Disabling or Enabling other controls based on the value entered.

For example:
A form that contains a combobox, a textbox, and a button (in that order). Suppose the combobox's text field is blank and the textbox underneath it is disabled (greyed out). When you make a selection using the enter key in the combobox it needs to enable the greyed out textbox AND move focus to the newly enabled textbox. If I don't call the form's Validate method first, using the SelectNextControl method would put the focus on the button because the textbox would not have been enabled yet. I hope this all makes sense and I hope someone can recommend an easier way to go about this. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top