Emanuele Doria

Emanuele Doria

  • NA
  • 100
  • 3.4k

wpf how i write on db from checkbox list

Oct 25 2018 12:40 PM
hello
i have application wpf where i create 30 checkboxes and check a range with condition read from database:
 
 
  1. <DataTemplate x:Key="DataTemplate_Level2">  
  2.            <CheckBox IsChecked="{Binding  Mode=OneWay}" Checked="CheckBox_Checked"  Height="30" Width="30" Margin="4,4,4,4"/>  
  3.        </DataTemplate>  
  4.   
  5.        <DataTemplate x:Key="DataTemplate_Level1">  
  6.            <ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate_Level2}">  
  7.                <ItemsControl.ItemsPanel>  
  8.                    <ItemsPanelTemplate>  
  9.                        <StackPanel Orientation="Horizontal"/>  
  10.                    </ItemsPanelTemplate>  
  11.                </ItemsControl.ItemsPanel>  
  12.            </ItemsControl>  
  13.        </DataTemplate>  
  14.          
  15.    </UserControl.Resources>  
  16.   
  17.      
  18.    <Grid>  
  19.            <StackPanel Orientation="Horizontal">  
  20.                <ItemsControl x:Name="lst"  ItemTemplate="{DynamicResource DataTemplate_Level1}" />  
  21.            <Button Click="Button_Click" Content="salva"/>  
  22.        </StackPanel>  
  23.    </Grid>  
codebehind:
 
  1. DB_Crew1Entities entita = new DB_Crew1Entities();  
  2.         List<OperazioniBettolina> row;  
  3.         List<List<bool>> lsts;  
  4.   
  5.         public UC_Orari()  
  6.         {  
  7.             row= entita.OperazioniBettolinas.ToList();  
  8.   
  9.             lsts = new List<List<bool>>();  
  10.   
  11.             for (int i = 0; i < row.Count(); i++)  
  12.             {  
  13.                 lsts.Add(new List<bool>());  
  14.   
  15.                 for (int j = 0; j < 30; j++)  
  16.                 {  
  17.                     //fill range of checkboxes read from db  
  18.                     lsts[i].Add(row[i].StratTime<= j && j < riga[i].EntTime);  
  19.   
  20.                 }  
  21.             }  
  22.   
  23.             InitializeComponent();  
  24.   
  25.             lst.ItemsSource = lsts;  
  26.   
  27.         }  
 
How can i write on db?
 if the user check other checkbox i should save another(new) range ::
 
  1. private void Button_Click(object sender, RoutedEventArgs e)  
  2.         {  
  3.             for (int i = 0; i < lsts.Count(); i++) ???? 
  4.             {  
  5.               ???????????????????????
  6.   
  7.             }  
  8.         }  
 

Answers (2)