Form Event Wizard - Fill in field

Trying to create a Form Event Wizard that fills in a field based on another field in the same table.

If “4RB-30-4 PKG 230/460/3/60 ODP” was entered in Part.PartDescription, and then the user chooses “87FG” as the Part.ClassID, then the Part.ShortChar03 field would be automatically filled in with “4RB”(the characters before the first “-”).

I made an attempt, but couldn’t get it to work.

private void Part_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case “ClassID”:
string[] pdesc = PartDescription.Split("-");
string prefix = pdesc[0];

		if(args.ProposedValue = "87FG")
			args.Row["ShortChar03"] = prefix;
		break;
}

}

End up with the following:
--------compile errors------------
Error: CS0103 - line 72 (971) - The name ‘PartDescription’ does not exist in the current context
Error: CS0266 - line 75 (974) - Cannot implicitly convert type ‘object’ to ‘bool’. An explicit conversion exists (are you missing a cast?)

** Compile Failed. **

Any help for a C# newbie would be much appreciated.

Make string var to hold args.ProposedValue, then compare that var with your constant “87FG”

That’ll solve the 2nd error. Don’t recall off the top of my head on how to reference the Part.PartDescription value.

args.Row[“PartDescription”].Split("-")

1 Like

if(args.ProposedValue == “87FG”)

Thanks for the assist. A few more little tweaks (single quotes around the ‘-’) and it works like a charm. Slowly overcoming my fear of C#.

{
	case "ClassID":
		string s = (args.Row["PartDescription"].ToString());
		string[] pdesc = s.Split('-');
		string prefix = pdesc[0];
			if(args.ProposedValue.ToString() == "87FG")
				args.Row["ShortChar03"] = prefix;
		break;
}
1 Like