E10 Customization - Add new row to UD26 on Form Load

Hi,

I’m wanting to customize the UD26 maintenance, where a new row is opened on form load and default fields are set. I don’t want the user to have to enter Key1 and Key2.

I have this code:

private void UD26Form_Load(object sender, EventArgs args)
{
	// Add Event Handler Code

	string userID = ((Ice.Core.Session)oTrans.Session).UserID;
	string companyID = ((Ice.Core.Session)oTrans.Session).CompanyID;

	EpiDataView edvUD26 = ((EpiDataView)(oTrans.EpiDataViews["UD26"]));

            // ----- error on next statement -----
	edvUD26.dataView.Table.Rows.Add(); // tried 0 and 1 here, too

	edvUD26.dataView[0]["Company"] = companyID;
	edvUD26.dataView[0]["Key1"] = "PickListLabel";
	edvUD26.dataView[0]["Key2"] = userID;

	edvUD26.Notify( new EpiNotifyArgs(oTrans, edvUD26.Row, edvUD26.Column) );

}

It compiles okay, but on the statement noted above gets the following error when I open UD26 maintenance:

    Message: Exception has been thrown by the target of an invocation.
    Inner Exception Message: Specified cast is not valid.

    (Complete error description below.)

Point me in the right direction?

Thanks,

Joe Trent

Application Error

Exception caught in: mscorlib

Error Detail

Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Specified cast is not valid.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

Client Stack Trace

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeCustomFormLoadIfExists(String methodName, Object sender, EventArgs e)
at Ice.Lib.Customization.CustomScriptManager.<>c__DisplayClass103_0.b__0()
at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)

Inner Exception

Specified cast is not valid.

at Ice.Lib.Framework.EpiTreeView.treeLoader(EpiTreeNode parentNode, EpiDataView treeView, EpiTreeBinding treeBinding, String filter)
at Ice.Lib.Framework.EpiTreeView.ResetTreeData(Boolean preserveNodeState)
at Ice.Lib.Framework.EpiTreeView.onNotification(EpiDataView view, EpiNotifyArgs ar, Boolean visibilityChanged)
at Ice.Lib.Framework.EpiTreeView.oDataView_EpiNotification(EpiDataView view, EpiNotifyArgs ar)
at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
at Ice.Lib.Framework.EpiDataView.Notify(EpiNotifyArgs args)
at Script.UD26Form_Load(Object sender, EventArgs args)

Use the function oTrans.GetNew(key1, key2, key3, key4, key5) followed by an oTrans.NotifyAll().

Why not add this as a post process of GetaNewUD26?

Then on your form load just call GetaNewUD26.

Just to offer an alternative, you might be able to take advantage of the ListChanged event so when a new row is added, you update the keys.

myDataView.ListChanged += (sender, args) =>
            {
                if (args.ListChangedType == ListChangedType.ItemAdded)
                {
                    (sender as EpiDataView).Table.Rows[args.NewIndex]["Key1"] = "YourKey1";
                    (sender as EpiDataView).Table.Rows[args.NewIndex]["Key2"] = "YourKey2";
                }
            }