This is my XAML code
<DataGrid x:Name="missiongrid" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Mission type" Width="320">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="UpCheckbox" Margin="10,10,0,0"
Content="Name"
Checked="UpCheckbox_Click"
>
</CheckBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Name="standardCheckbox" Margin="10,10,0,0" IsChecked= "{Binding Column1}" Checked="CheckBox_Click_1" Unchecked="UnCheckBox_Click_1" />
<TextBlock Text="{Binding Column2}" Padding="10,5,0,0" HorizontalAlignment="Left" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Location" Binding="{Binding Column3}"/>
</DataGrid.Columns>
</Datagrid>
I want all the checkbox in standardcheckbox to check when the Upcheckbox are checked during runtime. This is my code behind. Everything is run in a datagrid
myDataItems = new List<DataItem>();
myDataItems.Add(new DataItem { Column1 = true, Column2 = "Gambler", Column3 = "Jurassic Park", Column4 = "CasinoRoyal", Column5 = "JohnGramer" });
myDataItems.Add(new DataItem { Column1 = true, Column2 = "Gambler", Column3 = "Lord of the Ring", Column4 = "CasinoRoyal", Column5 = "JohnGramer" });
enter code here
myDataItems.Add(new DataItem { Column1 = false, Column2 = "Gambler", Column3 = "Harry potter", Column4 = "CasinoRoyal", Column5 = "JohnGramer" });
missiongrid.ItemsSource = myDataItems;
I try to add in this onCheck method, which is call when the checkbox is checked.
private void UpCheckbox_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < myDataItems.Count; i++)
{
myDataItems[i].Column1 = true;// not working
}
}
But it is not working? The checkbox didnt change at all during runtime, only the header checkbox are checked
what should I do?
Aucun commentaire:
Enregistrer un commentaire