I have a UD textbox on the Quote Entry Form that I’d like to set the color of, based on the value of that UD textbox field.
For example, if the value is “On File”, set the color to green. If the value is “Expired” then set the color to red.
If you only have those two choices, you may consider using a shape instead. They have an “enabled” and disabled" state that are pre-programmed to do the green/red with different messages for each. Then you can set the enabled/disabled in an EpiViewNotification. See below example.
Thank you Aaron for the code. I modified it for my application. It compiles successfully, but nothing is updated on the Quote Entry screen. I added a messagebox right after the private void QuoteHed_BeforeFieldChange to see if it is being triggered, but alas, it is not.
I’ve tried other events such as AfterRowChange, BeforeRowChange, and AfterFieldChange, but to no avail, same result. This is my modified code:
public class Script
{
private EpiTextBox txtVerStmntStatus;
public void InitializeCustomCode()
{
this.QuoteHed_Column.ColumnChanging += new DataColumnChangeEventHandler(this.QuoteHed_BeforeFieldChange);
this.txtVerStmntStatus = (EpiTextBox)csm.GetNativeControlReference("b58ae739-d838-41e8-b906-7ba0db9b4643");
}
public void DestroyCustomCode()
{
this.QuoteHed_Column.ColumnChanging -= new DataColumnChangeEventHandler(this.QuoteHed_BeforeFieldChange);
}
private void QuoteHed_BeforeFieldChange(object sender, DataColumnChangeEventArgs args)
{
MessageBox.Show("after row change QuoteHed triggered");
switch (args.Column.ColumnName)
{
case "VerStmntStatus_c":
if (string.IsNullOrEmpty((string)args.ProposedValue))
{
txtVerStmntStatus.UseAppStyling = false;
txtVerStmntStatus.BackColor = System.Drawing.Color.Red;
}
else
{
txtVerStmntStatus.UseAppStyling = false;
txtVerStmntStatus.BackColor = System.Drawing.Color.Yellow;
}
break;
// add more cases here if necessary
}
}
}
Got an update…
Seems the BeforeFieldChange event is triggered when creating a new quote. The messagebox appears after I type in a customer id and hit tab. However, it is still not changing the color.
In the customization settings at the top there is a field called UseAppStyling. Turn this to false for any field you need to manually set the color (or any styling) for. I see it is set in the code, but sometimes I have to manually change it to get colors to work.
Plop a couple more message boxes inside the if statement to make sure the expected path is followed. This will help confirm the code is being processed at all.
Well, yes actually, I do want the color of the textbox to change after clicking on the new Quote button, entering a customer ID (or searching for it), and hitting tab. At that point, I have a Method Directive (Erp.BO.Quote.GetCustomerInfo / Post-Processing) that populates the {QuoteHed.VerStmntStatus_c} UD field based on two UD fields in the customer record.
Based on the value that gets populated in {QuoteHed.VerStmntStatus_c}, which could be four values, I’d like the {QuoteHed.VerStmntStatus_c} field to be a certain color.