Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public partial class Datagrid
  2. {
  3. public int Id { get; set; }
  4. public string Name { get; set; }
  5. public string Location { get; set; }
  6. public Nullable<bool> IsChecked { get; set; }
  7. }
  8.  
  9. public partial class SampleDbContext : DbContext
  10. {
  11. public virtual DbSet<Datagrid> Datagrids { get; set; }
  12. }
  13.  
  14. public partial class MainWindow : Window
  15. {
  16. public ObservableCollection<Datagrid> data { get; set; }
  17. public List<Datagrid> lst = new List<Datagrid>();
  18. private SampleDbContext db;
  19. public MainWindow()
  20. {
  21. db = new SampleDbContext();
  22. lst = db.Datagrids.ToList();
  23. InitializeComponent();
  24. additems();
  25. }
  26.  
  27.  
  28. public void additems()
  29. {
  30. data = new ObservableCollection<Datagrid>(lst);
  31. this.DataContext = this;
  32. }
  33.  
  34. private void btn_Click(object sender, RoutedEventArgs e)
  35. {
  36. MessageBox.Show("Updated");
  37. this.db.SaveChanges();
  38. }
  39. }
  40.  
  41. <Grid>
  42. <ListView Name="lstCode" ItemsSource="{Binding data}" >
  43.  
  44.  
  45. <ListView.View>
  46.  
  47. <GridView>
  48. <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
  49. <GridViewColumn Header="Location" DisplayMemberBinding="{Binding Location}"/>
  50. <GridViewColumn Header="IsActive" Width="70">
  51. <GridViewColumn.CellTemplate>
  52. <DataTemplate>
  53. <CheckBox Name="chk" IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox>
  54. </DataTemplate>
  55. </GridViewColumn.CellTemplate>
  56. </GridViewColumn>
  57. </GridView>
  58. </ListView.View>
  59. </ListView>
  60. <Button Name="btn" Height="23" Margin="0,0,201,85" Content="Update" HorizontalAlignment="Right" VerticalAlignment="Bottom" RenderTransformOrigin="1.333,3.85" Click="btn_Click" />
  61.  
  62. </Grid>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement