Hi I have a WPF application, with a WPF datagrid with an observable collection of objects. Each object in the observable collection has a boolean variable that is represented by the check box in the data grid. What I am trying to do is make it so that when I check the box and make it "true" for one object of the collection, it makes the other objects of the collection be set to "false". In other words, when I click my data grid checkbox for one object, it unchecks the check box for the other objects in the collection. Its such a simple concept, but I have tried several ways to do this including using a property, but I get stack overflow cause it keeps looping through the collection forever, I tried using an event related to the clicking of the checkbox but I could not get the event to make all other objects in the data grid to be set to false because I couldn't figure out how to access the items in the datagrid to modify them. There must be a really easy way to do this that I am overlooking.
the WPF code it here:
<DataGrid x:Name="DataGrid1" AutoGenerateColumns="False" ItemsSource="{Binding CollectionOfThings}" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" Margin="0,0,0,124">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Column with a checkbox" Binding= "{Binding CheckBoxBooleanValue}" />
</DataGrid.Columns>
I have the c# code:
The collection contains objects from this simple class:
public class Thing
{
public bool CheckBoxBooleanValue {get; set;}
}
My main Window constructor in my WPF form creates the collection when the application starts:
public MainWindow()
{
ObservableCollection<Thing> CollectionOfThings;
Thing thing1 = new Thing();
CollectionOfThings.Add(thing1);
Thing thing2 = new Thing();
CollectionOfThings.Add(thing2);
}