High level explanation of start activity on custom screen

So I am able to end activity with my code in the dashboard and I can set the quantity using the value that I type into the dashboard.

Now I need to add some cell validation in. I don’t have any experience working the arguments and the properties so I am getting stuck. The code that the wizard gives me is shown below.

	private void Results_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 "LaborDtl_LaborQty":
			{
			MessageBox.Show("edit intitiated");
			}
			break;
		}
	}

I’ve added the message box to see when it fires, and the message box pops up any time I tab out of the field, so that’s good. I can also add in args.Row.CancelEdit(); and it will cancel the edit, which I will need later.

What I need to do is compare the proposed value to (RunQty - QtyCompleted), so if the labor qty is more than what is actually left to make, it stops them from putting that value in.

I can see the helpful properties that it provides, but I can’t figure out how to use them. I’ve tried putting this in right after the message box. It compiles successfully, but it kicks out after hitting the first var. If I comment out all of the var and the if statement, it will show both message boxes. (I’m skipping the extra math for now, just trying to get some if then statement to work)

			MessageBox.Show("edit intitiated");
			var RowNum2 = Convert.ToInt32(args.Row);
			var RunQ = Convert.ToInt32(MainGrid.Rows[RowNum2].Cells["JobOp_RunQty"].Value);
			var LabQ= Convert.ToInt32(args.ProposedValue);
			if (LabQ > RunQ)
			{
				MessageBox.Show("LaborQty cannot be more than required");
				args.Row.CancelEdit();
			}
			else
			MessageBox.Show("ok");
			}

I’m sure I’m doing a bunch of things wrong at once, but I’m trying hard to learn this, I’m just getting stumped on how to use the properties provided. With all of the other stuff that I’ve been dealing with grids, it’s been in a for loop with a row counter, so I’ve been able to use the RowNum as it counted. With this I have to get the value of the selected row, which I am assuming that I can use the args.Row, but I don’t know how to use it.

I know that this is pretty basic stuff, but I gotta start somewhere right?

Thanks in advance to anyone willing to help me out.

1 Like