tags:

views:

54

answers:

1

am having a set of checkbox in a stackpanel, i want to get the selected checkbox in my code..

how i can get those selected checkbox in a stackpanel

A: 

You can query the children of the stackpanel.

IEnumerable<CheckBox> selectedBoxes =
    from checkbox in this.stackPanel1.Children.OfType<CheckBox>()
    where checkbox.IsChecked.Value
    select checkbox;

foreach (CheckBox box in selectedBoxes)
{
    // do something 
}

Same query in lambda form

IEnumerable<CheckBox> selectedBoxes =
    this.stackPanel1.Children.OfType<CheckBox>()
    .Where(cb => cb.IsChecked.Value);
Anthony Pegram
You can make this easier with the OfType operator: `from cb in stackPanel1.Children.OfType<CheckBox>() where cb.IsChecked.Value select cb`. Saves the test in the `where` clause and the repeated casts.
itowlson
Good idea. I'll update it.
Anthony Pegram
hai itowlson,i can t understand wat you saying. can u tell me in some more detailed...
deep