Skip to Content
0

How to assign ChooseFrom list value to Edit-Text-Field in C#

Mar 21 at 07:04 AM

30

avatar image

Hi Experts,

I have a problem with a selected ChooseFrom list value assign to my Edit-Text-Field.

When I choose the ItemCode one from the List of Items, now I want to set the ItemName to another EditText.

I tried with below code, but most of the time I received the error message like 'General error'.

I have attached screenshot of my requirement.

Itemname = System.Convert.ToString(oDataTable.GetValue(1, 0));oItem = oForm.Items.Item("txtITMNM");oEdit = ((SAPbouiCOM.EditText)(oItem.Specific));oEdit.String = Itemname;

choosefromlist.png (16.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Roman Savelyev Mar 21 at 11:42 AM
0

Wonderful SAP sometimes does not allow you to write values into fields when the picker form is open (ChooseFromeListEvent &&! BeforeAction is still open). For the simplest cases, here is the code. It subscribes to the picker closing and remembers what needs to be done. Do not forget to add an event filter for the picker form type, if you use the event filter.

class PickerCallback<TSelected>
{
	private Application SboApplication { get; set; }
	private string PickerFormID { get; set; }
	private Form ParentForm { get; set; }
	private Action<Form, TSelected> SelectAction { get; set; }
	private TSelected Selected { get; set; }
	public PickerCallback(
		Application appObject,
		Form pickerForm,
		Form parentForm,
		TSelected selected,
		Action<Form, TSelected> selectAction )
	{
		SboApplication = appObject;
		SboApplication.ItemEvent += InvokeSelectAction; 
		PickerFormID = pickerForm.UniqueID;
		ParentForm = parentForm;
		SelectAction = selectAction;
		Selected = selected;
	}


	private void InvokeSelectAction( string FormUID, ref ItemEvent pVal, out bool BubbleEvent )
	{
		if ( FormUID == PickerFormID &&
			pVal.EventType == BoEventTypes.et_FORM_CLOSE &&
			!pVal.BeforeAction &&
			pVal.ActionSuccess )
		{
			try
			{
				SelectAction?.Invoke( ParentForm, Selected );
			}
			catch ( Exception ex )
			{
				...
			}
			finally
			{
				SboApplication.ItemEvent -= InvokeSelectAction; // Remove self from invokation list
				SboApplication = null; // Probably not necessary.
				ParentForm = null;
				SelectAction = null;
			}
		}
		BubbleEvent = true;
	}
}


Use:

ChooseFromListEvent eventDetails = ...; // !BeforeAction
DataTable selected = eventDetails.SelectedObjects;
if ( selected != null && selected.Rows.Count > 0 )
{
	var selectedPair = new KeyValuePair<string, string>( 
		        selected.GetValue( "AbsID", 0 ).ToString(), 
		        selected.GetValue( "Number", 0 ).ToString() );


	new PickerCallback<KeyValuePair<string, string>>(
		Application,
		Application.Forms.ActiveForm, // Picker Form
		documentForm, // Main form
		selectedPair,
		MyCflAction );
}

private static void MyCflAction( Form documentForm, KeyValuePair<string, string> pair )
{
        Items formItems = form.Items;
        EditText keyField = ...;
	EditText numField = ...;
	keyField.Value = pair.Key;
	numField.Value = pair.Value;
}

Show 1 Share
10 |10000 characters needed characters left characters exceeded

HI Roman Savelyev,

Thanks for you prompt replay,

I will check and let you know the same.

Thanks,

Chenna

0
Danilo Kasparian Mar 21 at 03:11 PM
0

Instead of setting the EditText, try to use the DBDataSource

As an example, some choosefromlist I did in the past without any problem, don`t forget to replace to your table and fields names.

               DbDataSource myDBDataSource = form.DataSources.DBDataSources.Item("MYTABLENAME");
  
                var iChoose = (ISBOChooseFromListEventArg)pVal;
                DataTable dataTable = iChoose.SelectedObjects;

                if (dataTable == null || dataTable.Rows.Count == 0)
                {
                    return;
                }

                string itemCode = dataTable.GetValue("ItemCode", 0).ToString();
                string itemName = dataTable.GetValue("ItemName", 0).ToString();

                myDBDataSource.SetValue("ITEMCODEFIELD", 0, itemCode);
                myDBDataSource.SetValue("ITEMNAMEFIELD", 0, itemName);
          
Share
10 |10000 characters needed characters left characters exceeded