cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member416544
Participant
0 Kudos

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;

Accepted Solutions (1)

Accepted Solutions (1)

former_member233854
Active Contributor
0 Kudos

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);
          

Answers (1)

Answers (1)

0 Kudos

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;
}

former_member416544
Participant
0 Kudos

HI Roman Savelyev,

Thanks for you prompt replay,

I will check and let you know the same.

Thanks,

Chenna