03-21-2018 7:04 AM - edited 02-04-2024 3:47 AM
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;
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for you prompt replay,
I will check and let you know the same.
Thanks,
Chenna
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.