Question: I have a datagrid bound to a list and each cells value is bound to unique booleans.

```
<UserControl.Resources>
    <Style TargetType="{x:Type DataGridCell}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Have1}" Value="True">
                <Setter Property="Background" Value="#263DDE36"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Have1}" Value="False">
                <Setter Property="Background" Value="#26FF5454"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

<DataGrid ItemsSource="{Binding AuditList}" AutoGenerateColumns="False" >
    <DataGrid.Columns>
        <DataGridTextColumn Header="Art1" Binding="{Binding Have1}"/>
        <DataGridTextColumn Header="Art2" Binding="{Binding Have2}"/>
        <DataGridTextColumn Header="Art2" Binding="{Binding Have3}"/>
    </DataGrid.Columns>
</DataGrid>

```

This works fine but I would like to change the binding "Have1", to the cells current string or bool value.

```
<DataTrigger Binding="{Binding DataCellsValue="True"}" Value="True">
    <Setter Property="Background" Value="#263DDE36"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataCellsValue="False"}" Value="False">
    <Setter Property="Background" Value="#26FF5454"/>
</DataTrigger>

```

How is this achieved? Ideally, I just want to use the one setter for all columns without duplicating setters for each columns cell.

Thanks!

Answer: 
Just use the standard library algorithms 

```
auto end = std::find(std::begin(array),std::end(array),0);
std::reverse(std::begin(array),end);
//And if you only want to print the non-zero values:
size_t effectiveArraySize = end - std::begin(array);

```

---

If the fixed size array is not part of your requirement, you should put your user data in a vector that automaticaly grows as large as you need, instead of using an array that might turn out to be too small:

```
std::vector<int> v;
while(true) {
    int t;
    cin >> t;
    if (t == 0) {
       break;
    }
    v.push_back(t);       
}
std::reverse(v.begin(),v.end());

```

That way, you don't have any sentinel values in your array / vector to begin with.
*Note: Using the respective functions from the STL (`std::reverse` and `std::find`) is better, I was just guessing that you are bound to implement this on your own.*

---

*Step one*: Write a proper reverse function. One that takes (a pointer to) the beginning as well as (a pointer to) the end of the range that should be reversed.

*Step two*: Write a function to find (the first position of) your sentinel in an array (given via beginning and end, again)

*Step three*: Connect the two: Reverse from the beginning to the position of your sentinel.

Example without templates:

```
void reverse(int * from, int * to) {
  while ((to - from) > 1) {
    --to;
    int temp = *from;
    *from = *to;
    *to = temp;
    ++from;
  }
}

int const * find(int const * from,
                 int const * const to,
                 int const value) {
  while ((from != to) && (*from != value)) {
    ++from;
  }
  return from;
}

void reverse_until (int * const from,
                                  int * const to,
                                  int const sentinel) {
  int const * const position_sentinel = find(from, to, sentinel);
  reverse(from, from + (position_sentinel - from));
  // return the sentinel position from this function
  // if you want only the reversed part
}

```

Tested with:

```
int main() {
  int test[10];
  for (size_t i = 0; i < 10; ++i) {
    test [i] = i + 1;
  }
  reverse_until (test, test + 10, 6);
  copy(test, test + 10, ostream_iterator<int>{cout, " "});
  return 0;
}

```

[(live here)](http://ideone.com/GYa4aT)