using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Data; using System.Data.OleDb; using WPF9112.NorthwindDataSetTableAdapters; using System.Windows.Shapes; namespace WPF9112 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class DatasetCRUDExample : Window { public class CustomerDataProvider { private CustomersTableAdapter adapter; private NorthwindDataSet dataset; public CustomerDataProvider() { dataset = new NorthwindDataSet(); adapter = new CustomersTableAdapter(); adapter.Fill(dataset.Customers); } public DataView GetCustomers() { return dataset.Customers.DefaultView; } } } }
<Window x:Class="WPF9112.DatasetCRUDExample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WPF9112" xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" Title="MyWindow" Height="900" Width="1200" WindowState="Maximized" WindowStyle="ThreeDBorderWindow" removed="Black" BorderBrush="Red" Foreground="White" FontSize="30" FontWeight="Bold" AllowsTransparency="False" AllowDrop="True" IsManipulationEnabled="True" UseLayoutRounding="True" xmlns:my="clr-namespace:System;assembly=mscorlib"> <Window.Resources> <!-- create an instance of our DataProvider class --> <ObjectDataProvider x:Key="CustomerDataProvider" ObjectType="{x:Type local:}" /> <!-- define the method which is invoked to obtain our data --> <ObjectDataProvider x:Key="Customers" ObjectInstance="{StaticResource CustomerDataProvider}" MethodName="GetCustomers"/> <my:Boolean x:Key="CanUserAddRows1">True</my:Boolean> <my:Boolean x:Key="CanUserDeleteRows1">True</my:Boolean> </Window.Resources> <Grid Width="1200" Height="900" Name="Mygrid" removed="Black"> <Grid.RowDefinitions> <RowDefinition Height="40*" /> <RowDefinition Height="40*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40*" /> <ColumnDefinition Width="40*" /> <ColumnDefinition Width="40*" /> </Grid.ColumnDefinitions> <Border BorderBrush="Red" BorderThickness="1" Grid.ColumnSpan="29" Grid.RowSpan="28" Height="762" HorizontalAlignment="Left" Name="myBorder" VerticalAlignment="Top" Width="1188"> <dg:DataGrid ItemsSource="{Binding}" AutoGenerateColumns="True" Height="761" Name="mygrid" Width="1186" HorizontalGridLinesBrush="Red" VerticalGridLinesBrush="Red" AlternatingRowBackground="Azure" AlternationCount="1" RowBackground="Cornsilk" removed="WhiteSmoke" FontSize="20" HorizontalScrollBarVisibility="Visible" MinRowHeight="10" BorderBrush="Red" VerticalScrollBarVisibility="Visible" RowDetailsVisibilityMode="Visible" IsManipulationEnabled="True" FrozenColumnCount="1"></dg:DataGrid> </Border> <Button Grid.Column="3" Grid.ColumnSpan="3" Grid.Row="28" Grid.RowSpan="2" Height="41" HorizontalAlignment="Left" Name="btnOpen" VerticalAlignment="Top" Width="85" Content="Open" Background="Green" /> </Grid> </Window>
<ObjectDataProvider x:Key="CustomerDataProvider" ObjectType="{x:Type local:}" />
{x:Type local:}
{x:Type local:CustomerDataProvider}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)