W. Christopher Moses
W. Christopher Moses

Reputation: 73

Determine which Monotouch.Dialog Checkbox was checked/unchecked

I have a list of people that I want to display with checkboxes next to their names. When an CheckBoxElement (person) is checked or unchecked, I need to handle the event.

        List<CheckboxElement> cbPersonElements = new List<CheckboxElement> ();
        CheckboxElement tmpCheckbox = new CheckboxElement ("");
        foreach (ABPerson itemPerson in _people) {
            tmpCheckbox = new CheckboxElement (itemPerson.LastName);
            cbPersonElements.Add(tmpCheckbox);
        }

And then I add the list when I create the RootElement:

        RootElement _rootElement = new RootElement ("People List"){
            new Section ("People"){
                cbPersonElements
        }

How should I add a handler that will allow me to detected which CheckBoxElement was clicked.

I can't attach one to tmpCheckbox, that value changes with each iteration through the loop.
Seems like it should be simple, but I can't see it. Thanks.

Upvotes: 0

Views: 275

Answers (1)

Jason
Jason

Reputation: 89204

you should be able to use a ValueChanged handler

foreach (ABPerson itemPerson in _people) {
  tmpCheckbox = new CheckboxElement (itemPerson.LastName);
  tmpCheckbox.ValueChanged += delegate {
    // do something here based on tmpCheckbox.Value
  };
  cbPersonElements.Add(tmpCheckbox);
}

Upvotes: 1

Related Questions