Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 2.08 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Keeping a datagrid in sync with a mysql database
  2. class ConDataProvider
  3. {
  4.     private MySqlDataAdapter adapter;
  5.     private Data data;
  6.     private DataTable table;
  7.  
  8.     public ConDataProvider(string query)
  9.     {
  10.         data = new Data();
  11.         table = new DataTable("con_FullGrid");
  12.         adapter = data.getAdapter(query);
  13.         adapter.Fill(table);
  14.     }
  15.     public DataView GetDView()
  16.     {
  17.             dv = new DataView();
  18.             dv.Table = table;
  19.             return dv;
  20.     }
  21. }
  22.        
  23. <Window x:Class="HelioWPF_Alpha01.MainWindow"
  24.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  25.     xmlns:local="clr-namespace:HelioWPF_Alpha01"
  26.     xmlns:sys="clr-namespace:System;assembly=mscorlib"
  27.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  28.     Title="MainWindow" Height="676" Width="924" MinHeight="300" MinWidth="463" Background="{x:Null}">
  29. <Window.Resources>
  30.     <ObjectDataProvider x:Key="ConDataProvider" ObjectType="{x:Type local:ConDataProvider}">
  31.         <ObjectDataProvider.ConstructorParameters>
  32.             <sys:String>SELECT * FROM con_FullGrid</sys:String>
  33.         </ObjectDataProvider.ConstructorParameters>
  34.     </ObjectDataProvider>
  35.     <ObjectDataProvider x:Key="btable" ObjectInstance="{StaticResource ConDataProvider}"
  36.                         MethodName="GetDView"/>
  37.  
  38. </Window.Resources>
  39. <Grid Name="mainGrid" DataContext="{Binding Source={StaticResource btable}" KeyDown="mainGrid_KeyDown" FlowDirection="LeftToRight" >
  40.     <DataGrid AutoGenerateColumns="True" ItemsSource="{Binding}" Name="dataGrid1" FrozenColumnCount="20" RowHeight="25" Grid.ColumnSpan="4" ColumnWidth="*" MouseDoubleClick="dataGrid1_MouseDoubleClick" SelectionMode="Single" Grid.Row="2" Grid.Column="1" TabIndex="1" GotKeyboardFocus="dataGrid1_GotKeyboardFocus">
  41.         <DataGrid.AlternatingRowBackground>
  42.             <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  43.                 <GradientStop Color="Black" Offset="0" />
  44.                 <GradientStop Color="#16436DF8" Offset="0" />
  45.             </LinearGradientBrush>
  46.         </DataGrid.AlternatingRowBackground></DataGrid>
  47. </Grid>