Code to make a button the default action, triggerable by the enter key

Simple question… not such a simple answer to find in the documentation.

I have 3 text fields and a button. I want to be able to hit enter and it activate the button.

Thanks,
Greg

We may need a little more detail. Does an ENTER press on ANY of the text boxes click the same button?

TextBox1.KeyPress += (o,e) =>
{
MyButton1.PerformClick();
};

You could also turn on KeyPreview = true on the form and do a keypress check on the form instead of individual controls.

You could use a Row Rule wizard to scan for your conditions and then have a custom rule action to perform the enabling of the button.

> private void CreateRowRuleQuoteDtlDrawNumContains_Constant_NullValue()
> 	{
> 		// Description: DrawNumBlank
> 		// **** begin autogenerated code ****
> 		RuleAction[] ruleActions = new RuleAction[0];
> 		// Create RowRule and add to the EpiDataView.
> 		// Dummy Context Object
> 		object contextObject = null;
> 		RowRule rrCreateRowRuleQuoteDtlDrawNumContains_Constant_NullValue = new RowRule("QuoteDtl.DrawNum", RuleCondition.Contains, "Constant: NullValue", new RowRuleActionDelegate2(this.QuoteDtlDrawNumContainsConstantNullValue_CustomRuleAction), contextObject);
> 		((EpiDataView)(this.oTrans.EpiDataViews["QuoteDtl"])).AddRowRule(rrCreateRowRuleQuoteDtlDrawNumContains_Constant_NullValue);
> 		// **** end autogenerated code ****
> 	}
> 
> private void QuoteDtlDrawNumContainsConstantNullValue_CustomRuleAction(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
> 	{
> 		// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
> 		// ** put custom Rule Action logic here
> 		//Disable Deallcation Reason combo Box
> 		EpiUltraCombo cmbReason = (EpiUltraCombo)csm.GetNativeControlReference("d8b2f49a-88af-4ad0-add8-f3d3aa73c2ae");
> 		//cmbReason.Enabled = false;
> 		//Disable Deallocation Button
> 		EpiButton btnDeselect = (EpiButton)csm.GetNativeControlReference("12eb42cf-7117-4a63-8adc-0c4ff559443e");
> 		btnDeselect.Enabled = false;
> 	}

Edit: Read your question more, I think Chris actually understood what you were asking :slight_smile:

Much like the myriad of search modal windows used in epicor (Sales Order Search, Customer Search). The ‘Search’ button appears to have a dotted line box inside the button. And regardless of which search field one types in, pressing the enter key activates the search.

I was thinking this would be a property. I believe VB used to call it .Default. Putting the code in each text boxes keypress event seems overkill.

Greg

It should only be dotted (and accept keypresses) if it is focused. Just focus a different element. MyText.Focus(); Test it out manually, set the focus in your text field and see if it still behaves the same. If it does, maybe there is some form keyhandling in the works you could disable.

Also make sure the form doesn’t have an AcceptButton. MyForm.AcceptButton = null;