binding and grouping OptionButtons

Mattia Ryffel

Hi,

Im trying to bind and group some Optionbuttons by code.
I usually do this by xml, and works fine. Here i've a problem with grouping and binding to the datasource.
I cant group nor databind the optionbuttons before the form add or it leads to a nullpointer exception, but if i do that after the form load nothing happens even if i reload the form...

any hint? what i'm doing wrong?




swaForm = Form.CreateNewForm("SampleForm", "Sample" + SwissAddonFramework.Utils.UniqueStringGenerator.Next(2));

// Set form width and height
swaForm.Height = 305;
swaForm.Width = 600;
swaForm.Value = "UI Grid sample";

// Option buttons
// Create a user Datasource for the option buttons
swaUserDS = UserDatasource.CreateNew();
swaUserDS.Length = 1;
swaUserDS.DataSourceType = UserDatasource.DataType.ShortText;
swaUserDS.UniqueID = "OpBtnDS";
swaForm.AddUserDatasource(swaUserDS);

// No Grouping
OptionButton optNo = OptionButton.CreateNew("optNo");
optNo.Left = 480;
optNo.Top = 160;
optNo.Value = "No grouping";
swaForm.AddItem(optNo);

// CardCode
OptionButton optCard = OptionButton.CreateNew("optCard");
optCard.Left = 480;
optCard.Top = 180;
optCard.Value = "Card Code";
swaForm.AddItem(optCard);

//Load the form
swaForm.Load();

optNo.DataBind.SetBind(true, "OpBtnDS");
optCard.GroupWith("optNo");
optCard.DataBind.SetBind(true, "OpBtnDS");

Marco Schweighauser

Hello Mattia,

I think you have first to bind the OptionButton before Grouping it.

optCard.GroupWith("optNo");
optCard.DataBind.SetBind(true, "OpBtnDS");


change to:

optCard.DataBind.SetBind(true, "OpBtnDS");
optCard.GroupWith("optNo");

Mattia Ryffel

have you got a sample? or just specify the order of actions to follow...

create form
add buttons to form
add ds to form
form.load
bind
group

this order gives me:
Not allowed when the datasource is already loaded in SAP

i think i tried all the possible combinations of the actions listed above

Marco Schweighauser

Hello Mattia, this should work:


Form frm = Form.CreateNewForm("test", SwissAddonFramework.Utils.UniqueStringGenerator.Next())
frm.Value = "Test form"

Dim usdSalesPrice As UserDatasource = UserDatasource.CreateNew("usdSP")
frm.AddUserDatasource(usdSalesPrice)

OptionButton optOldSalesPrice = OptionButton.CreateNew("optOldSP")
optOldSalesPrice.Value = "Sales price old"
optOldSalesPrice.DataBind = DataBind.CreateNew("usdSP")
optOldSalesPrice.DataBind.DataBound = True
frm.AddItem(optOldSalesPrice)

optNewSalesPrice = OptionButton.CreateNew("optNewSP")
optNewSalesPrice.Value = "Sales price"
optNewSalesPrice.DataBind = DataBind.CreateNew("usdSP")
optNewSalesPrice.DataBind.DataBound = True
frm.AddItem(optNewSalesPrice)

frm.Load()
optNewSalesPrice.GroupWith(optOldSalesPrice.UniqueID)


Attentions its VB .Net code ! But in C# its the same, only ; are missing ;)
0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post