Change Ultragrid row color with row rule based on column value

I have an UltraGrid in a customization that is bound to a temp table created in the customization. Everything works well except that I want to change the row color based on the value of a column called “ProcessFlag”. When the value is “NEW”, I want the SettingStyle,OK (green). when the value is “DUPE”, I want SettingStyle.Warning (yellow). Red is too harsh and orange would have been preferred if available, so yellow will have to do. Any other value should be the default. I tried to use RowRules but couldn’t get them to work. Couldn’t get them to work on a single cell, let alone an entire row.

RuleAction raNew = RuleAction.AddControlSettings(this.oTrans, "edvTrans.ProcessFlag", SettingStyle.OK);
RuleAction raDupe = RuleAction.AddControlSettings(this.oTrans, "edvTrans.ProcessFlag", SettingStyle.Warning);
RowRule rrNewTrans = new RowRule("edvTrans.ProcessFlag", RuleCondition.Equals, "NEW", raNew);
RowRule rrDupeTrans = new RowRule("edvTrans.ProcessFlag", RuleCondition.Equals, "DUPE", raDupe);
((EpiDataView)(this.oTrans.EpiDataViews["edvTrans"])).AddRowRule(rrNewTrans);
((EpiDataView)(this.oTrans.EpiDataViews["edvTrans"])).AddRowRule(rrDupeTrans);

Any guidance would be welcome, thanks.

I searched for RowRule and found code that someone got working but still no luck for me. I did find where I went wrong on getting the entire row to highlight. So no syntax errors now but still no luck in getting the rows to highlight.

	ControlSettings styleOrange = new ControlSettings();
	styleOrange.BackColor = System.Drawing.Color.FromArgb(255,128,128);
	RuleAction raNew = RuleAction.AddRowSettings(this.oTrans, "edvTrans", true, SettingStyle.OK);
	RuleAction raDupe = RuleAction.AddRowSettings(this.oTrans, "edvTrans", true, styleOrange);
	RuleAction[] rasNew = new RuleAction[] { raNew };
	RuleAction[] rasDupe = new RuleAction[] { raDupe };
	RowRule rrNewTrans = new RowRule("edvTrans.ProcessFlag", RuleCondition.Equals, "NEW", rasNew);
	RowRule rrDupeTrans = new RowRule("edvTrans.ProcessFlag", RuleCondition.Equals, "DUPE", rasDupe);
	((EpiDataView)(this.oTrans.EpiDataViews["edvTrans"])).AddRowRule(rrNewTrans);
	((EpiDataView)(this.oTrans.EpiDataViews["edvTrans"])).AddRowRule(rrDupeTrans);

I used the Rule Wizard, and it generated the following code:

public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		CreateRowRuleShipToAddress2Contains_E10TEST();;
		// End Wizard Added Custom Method Calls
	}

	private void CreateRowRuleShipToAddress2Contains_E10TEST()
	{
		// Description: Test1
		// **** begin autogenerated code ****
		RuleAction warningShipTo_RowAction = RuleAction.AddRowSettings(this.oTrans, "ShipTo", true, SettingStyle.Warning);
		RuleAction[] ruleActions = new RuleAction[] {
				warningShipTo_RowAction};
		// Create RowRule and add to the EpiDataView.
		RowRule rrCreateRowRuleShipToAddress2Contains_E10TEST = new RowRule("ShipTo.Address2", RuleCondition.Contains, "E10TEST", ruleActions);
		((EpiDataView)(this.oTrans.EpiDataViews["ShipTo"])).AddRowRule(rrCreateRowRuleShipToAddress2Contains_E10TEST);
		// **** end autogenerated code ****
	}

Other than not being orange, that does the trick

For whatever reason, the row rules were not working on the grid when UseAppSettings was set to true. Maybe due to it being bound to a table that was created in the customization script and manually added to the EpiDataView collection in oTrans. Since this is a utility program, I’m not concerned if the appearance of the grid conforms aesthetically with the rest of the screen

Thanks everyone for the suggestions.

@BBussey - Thanks! Your code snippet helped me figure out how to set a cell color to something other than the SettingStyles of OK (green), Warn (red), Highlight (blue), or Error (yellow? I haven’t tested).

I got a request to highlight a $0 cost cell in Order Entry orange, so I created a Custom Row Rule, set the style to OK, and then added your color code to the script editor and overwrote ‘SettingStyle.OK’ with ‘settingOrange’. Thanks!

image

image
image

2 Likes

Quick Reference in case a newbie like me needs to tweak some colors in some old VB customization and don’t know what’s available. These were some of the colors available found in Epicor10.2.700

SettingStyle.OK = green
SettingStyle.Error = red
SettingStyle.Highlight = blue
SettingStyle.Warning = yellow

1 Like