How to read CheckBox from Matrix
John Slaats
Hi,If have created a Matrix with a text column and a checkbox column.
Now I can read the values of the text column with Matrix.Getvalue.
But I cannot read the checkbox with Getvalue.
Can someone tel me how to read the value of the checkbox.
Kind regards,
John
Anders Olsson
Hello John,CheckBox values can only be accessed by attaching a datasource and do the get/set on the datasource. Here's an example of how to do that:
///
/// This method demonstrates how to databind a checkbox and how to get its current checked state.
///
private void howToDatabindCheckboxes()
{
// Generate a Unique ID for the datasource
string datasourceUID = UniqueStringGenerator.Next();
// Create a user datasource
UserDatasource dsCheckbox = UserDatasource.CreateNew(datasourceUID);
_b1Form.AddUserDatasource(dsCheckbox);
_b1Form.Update();
// Create a checkbox
CheckBox chk = CheckBox.CreateNew(UniqueStringGenerator.Next());
chk.SetPosition(10, 10);
chk.Width = 110;
chk.Value = "This is a checkbox";
_b1Form.AddItem(chk);
// Create a button
Button btnChk = Button.CreateNew(UniqueStringGenerator.Next());
btnChk.SetPosition(130, 10);
btnChk.Width = 100;
btnChk.Value = "Get checked state";
_b1Form.AddItem(btnChk);
// Create a DataBind object bound to the datasource
DataBind dbCheckbox = DataBind.CreateNew(datasourceUID);
dbCheckbox.DataBound = true;
// Attach the DataBind object to the checkbox
chk.DataBind = dbCheckbox;
// Code to be executed when the button is clicked
SwissAddonFramework.UI.EventHandling.ItemEvents.ClickEventHandler btnChkDelegate = delegate(SwissAddonFramework.UI.EventHandling.ItemEvents.Click e)
{
// If the checkbox has never been changed, it will have the value "".
// Otherwise it will be "Y" or "N" depending on the checked state.
string msg = "Not checked";
if (dsCheckbox.Value == "Y")
{
msg = "Checked";
}
SwissAddonFramework.UI.Dialogs.MessageBox.Show(msg, "OK");
};
btnChk.AddHandler_Click(ModeComponent.FormModes.ALL, null, btnChkDelegate);
}
Kind regards,
Anders Olsson
John Slaats
Thank you Anders,This is a very clear example, I understand the solution for a checkbox on a form.
But how does this apply to a checkbox in a column in a Matrix?
Kind regards,
John Slaats
0
Please sign in to leave a comment.
Comments
0 comments