微软的Toolkit 提供了WPF 的DataGrid 控件
下载并安装控件:http://www.codeplex.com/wpf
安装完后,可以看到工具栏多了几个控件
向WPF窗口 拖进去DatePicker 和DataGrid 和几个文本框和按钮
Xaml:
<Window x:Class="HomeFinance.winPay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="winPay" Height="600" Width="800" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" Loaded="Window_Loaded">
<Grid>
<my:DataGrid Margin="0,185,0,26" Name="dataGrid1" AutoGenerateColumns="True" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,12,0,0" Name="txtItem" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="267,12,0,0" Name="txtAmount" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,12,215,0" Name="txtDate" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,51,0,0" Name="txtRemark" VerticalAlignment="Top" Width="120" />
<Button Height="23" HorizontalAlignment="Left" Margin="213,51.843,0,0" Name="btnAddItem" VerticalAlignment="Top" Width="75" Click="btnAddItem_Click">添加</Button>
<Label Height="28" HorizontalAlignment="Left" Margin="12,10,0,0" Name="label1" VerticalAlignment="Top" Width="68">消费项目:</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="204,10,0,0" Name="label2" VerticalAlignment="Top" Width="65">消费金额:</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="393,10,0,0" Name="label3" VerticalAlignment="Top" Width="44">日期:</Label>
<my:DatePicker Height="24" HorizontalAlignment="Right" Margin="0,11,162,0" Name="datePicker1" VerticalAlignment="Top" Width="35" SelectedDateChanged="datePicker1_SelectedDateChanged" />
<Label Height="28" HorizontalAlignment="Left" Margin="34,51,0,0" Name="label4" VerticalAlignment="Top" Width="38">备注:</Label>
<StatusBar Height="20" Name="statusBar1" VerticalAlignment="Bottom">
<StatusBarItem Name="Status" />
</StatusBar>
</Grid>
</Window>
c#:
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.Shapes;
using System.Data.OleDb;
using System.Data;
namespace HomeFinance
{
/// <summary>
/// winPay.xaml 的交互逻辑
/// </summary>
public partial class winPay : Window
{
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\..\\..\\MyMoney.mdb";
public winPay()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadDataGrid();
}
private void LoadDataGrid()
{
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM Expen", conn);
DataSet ds = new DataSet();
oda.Fill(ds);
dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
}
}
private void datePicker1_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
txtDate.Text = datePicker1.SelectedDate.ToString();
}
private void btnAddItem_Click(object sender, RoutedEventArgs e)
{
using (OleDbConnection conn = new OleDbConnection(connString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO Expen ( 消费金额, 消费者, 消费日期, 备注 ) Values('" + txtAmount.Text + "','" + txtItem.Text+ "','" + txtDate.Text +"','" + txtRemark.Text + "')", conn);
cmd.ExecuteNonQuery();
}
LoadDataGrid();
}
}
}
调用了一个Access的数据库, 本想尝试一下AdoEF 但没有找打 Access 的 Provider 那位朋友知道那里可以获得,请发帖告诉我。
上面是示例运行后
分享到:
相关推荐
WPFToolkit(DataGrid)是一个安装包,通过安装之后才能使用其框架。
WPF之DataGrid使用示例WPF之DataGrid使用示例WPF之DataGrid使用示例
本程序实现功能: 1.DataGrid数据的显示、修改与保存 2.DataGrid数据导入Excel
WPFDataGrid WPF DataGrid LINQtoSQL示例程序
wpf 动态合并datagrid表头单元格
wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf示例wpf...
WPFTookit DataGrid_DataTableSample,DataGrid_LinqToSqlSample,DataGridBasicSample, 示例程序
WpfToolkit, WPF工具包 fork的工具包( https DotNetProjects.Wpf. 工具包 Nugethttps://www.nuget.org/packages/DotNetProjects.Wpf.Toolkit/电子邮件信息WPF工具包( https://wpf.co
结合实例很好的讲解了DataGrid中数据绑定,与数据操作即增删改查,还有分页功能。适合初学者快速的掌握DataGrid 的典型应用
WPF中的DataGrid合并单元格,模板列内嵌套DataGrid,非真正合并
VS2010WPF控件_WPFToolkit.rar
Microsoft Visual Studio 2008 WPF Toolkit 安装包
Extended WPF Toolkit 可以说是WPF Toolkit 的一个补充,也包含了许多WPF 控件供开发者使用
WPF ToolKit Chart.doc
wpf的DataGrid中,添加某一列的合计,并在最下方固定显示。本列子不使用ToolKit(有3.5和4.0的限制),添加一个类,重写DataGrid。可以在DataGrid上下左右绑定一个DataGrid,类似Footer属性。示例可直接运行,简单...
wpf通过datagrid操作数据库,实现datagrid增删改操作。
微软推出的WpfToolKit的源代码,可以研究和定制自己的控件
Extended WPF Toolkit - 3.0.0
WPF中DataGrid里面的Checkbox实现单选关键代码, 文档里面的代码复制粘贴即可实现!本人也是项目需要写的一个功能11行代码实现此功能! 希望可以帮助到你们!
wpf扩展控件库,具体使用参照https://github.com/xceedsoftware/wpftoolkit