Need to set/get the state of programmatically created checkboxes

Roshan0Roshan0 Member
edited August 28 in Xamarin.Mac

Here's my code:
List<NSButton> CheckList = new List<NSButton>();
int x = 25;
int y = 20;
for (int i = 1; i <= 10; i++)
{
NSButton checkbox = new NSButton(new CGRect(x, y + (y * i + 12 * 4), 100, 40));
checkbox.SetButtonType(NSButtonType.Switch);
checkbox.Title = "CheckBox " + i;
CheckList.Add(checkbox);
}
View.Subviews = CheckList.ToArray();
//A button action to select all checkboxes that contains "CheckBox" in its title
SelectAll.Activated += (a, b) => {
//Storing all the views of checkboxes that contains title "CheckBox".
var checkboxes = View.Subviews.Where(xy=>xy.AccessibilityTitle.Contains("CheckBox"));
foreach(var c in checkboxes) {
//I tried the following but failed. The below code shows error.
(NSButton)c.State = NSCellStateValue.On;
}
};
Can anyone help me on this?

Best Answer

  • Roshan0Roshan0
    Accepted Answer

    Sorry, identified the problem. Forget to add the parentheses. ((NSButton)c).State = NSCellStateValue.On;

Answers

  • Roshan0Roshan0 Member
    Accepted Answer

    Sorry, identified the problem. Forget to add the parentheses. ((NSButton)c).State = NSCellStateValue.On;

Sign In or Register to comment.