Problem getting Image-UDF onto mainform
Fabian Krull
Hy all,i just tried to get a UDF-PictureBox onto the mainform (Articles) with only partial success.
What i want:
in simple words, a copy of some picture-UDFs on the main form _with_ the option to change images.
How far i got:
Adding the new picturebox was no problem - as well as diplaying the actual picture - all works.
The problems start when i try to implement the change-picture function. I tried several approaches - sadly none of them work.
i appended a simple test-code to demonstrate the issues. this code is not exactly the one i tried, it implements all the different tries i did.
[CODE]
try
{
SwissAddonFramework.UI.EventHandling.ItemEvents.ClickEventHandler clickEvent =
delegate(SwissAddonFramework.UI.EventHandling.ItemEvents.Click cl)
{
try
{
//the two ways i tried to reference the UDF. Same results for both ways
PictureBox pb = pVal.Form.UDFForm.Items["U_cpBildOrder1"] as PictureBox;
//i think this is the "best-practice" way, is it?
PictureBox pb = PictureBox.GetFromUID(pVal.Form.UDFForm, "U_cpBildOrder1");
//tried to simulate a click on the UDF - no result, not even an Exception
pb.Click(SwissAddonFramework.UI.Components.Item.ClickType.Double);
//directly set the image - no result, also no exception
//(BUT: if i do not load item-data before clicking my dummy, it works)
pb.Picture = @"00.jpg"; //also tried an absolute path - same result
//check: setting a text-udf
//this works, even if the code above has failed to set the image
TextEdit te = TextEdit.GetFromUID(pVal.Form.UDFForm, "U_cpZusText");
te.Value = "asdasddasdasd";
//some things i also tried - most of it makes no sense, but i'm despaired, so i tried anyway...
pb.Refresh();
pb.Update();
pVal.Form.Update();
pVal.Form.UDFForm.Update();
}
catch(Exception exx)
{
System.Windows.Forms.MessageBox.Show(exx.Message, "Error");
}
};
//this is my testbox on the mainform, in final this one shall display the image, wich i already accomplished within another testcase.
//in this case it is mainly a PictureBox-Button-Perversion
PictureBox test = PictureBox.CreateNew("testPic");
test.Left = 0;
test.Top = 0;
test.Width = 100;
test.Height = 100;
test.Visible = true;
pVal.Form.AddItem(test);
pVal.Form.Update();
test.AddHandler_Click(ModeComponent.FormModes.ALL, null, clickEvent);
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error");
}
return true;
[/CODE]
Hopefully, anybody can halp - this functionality is kind of critical to the imminent switch to SAP.
Thanks in advance,
Fabian Krull
Anders Olsson
Hi Fabian,I tried your code and got the same result.
When using the UI API PictureBox object directly (without coresuite framework) the result is the same:
SAPbouiCOM.Form sapForm = SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.Item(pVal.Form.UDFForm.UniqueID);
SAPbouiCOM.PictureBox pb = (SAPbouiCOM.PictureBox)sapForm.Items.Item("U_Picture").Specific;
pb.Picture = "newpicture.jpg";
-> The PictureBox.Picture property still has the original value.
It seems that once it has been set it cannot be changed.
Here is a workaround you can try - update the image file through the DI and reload the form:
SAPbobsCOM.Company company = SwissAddonFramework.B1Connector.GetB1Connector().Company;
SAPbobsCOM.Items item = (SAPbobsCOM.Items)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
item.GetByKey(pVal.BusinessObjectKeyString);
item.UserFields.Fields.Item("U_Picture").Value = "newpicture.jpg";
int err = item.Update();
if (err != 0)
{
string errMsg = company.GetLastErrorDescription();
throw new Exception(string.Format("{0}: {1}", err.ToString(), errMsg));
}
pVal.Form.Close();
Form.OpenFormByKey("4", pVal.BusinessObjectKeyString);
Regards,
Anders
Fabian Krull
Hello Anders,thanks for your reply but i _just_ figured out how to do this and implementing it into our production system..
the solution to this was much simpler than i thought, i just went down the wrong path
for all of you who seek knowledge
[CODE]
PictureBox test = PictureBox.CreateNew("testPic");
test.Left = 0;
test.Top = 0;
test.Width = 100;
test.Height = 100;
test.Visible = true;
//now here's the magic^^
test.DataBind = DataBind.CreateNew();
test.DataBind.SetBind(true, "U_cpBildOrder1", "OITM");
pVal.Form.AddItem(test);
pVal.Form.Update();
[/CODE]
using this approach right away gives the picturebox the full functionality, including doubleclick and ctrl+doubleclick etc...
Greetz
Fabian Krull
Anders Olsson
Hi Fabian,Nice one, thanks for sharing the solution!
Anders
0
Please sign in to leave a comment.
Comments
0 comments