WPF DataGrid 绑定DataSet数据 自动生成行号
1、绑定数据:dataGrid1.ItemsSource = dataSet.Tables[0].DefaultView;
注意:在创建DataGrid 时可以通过AutoGenerateColumns 属性设置列是否自动生成,从而加入自定义列。如果DataGrid 中同时包含“自动生成列”与“用户自定义列”,则首先创建“用户自定义列”。DataGrid 支持的四种列及其数据类型见下表:

DataGrid绑定列名、数据列代码:
1 <DataGrid.Columns>
2 <DataGridTextColumn Header="客户编码" Binding="{Binding CustomerCode}"/>
3 <DataGridTextColumn Header="客户名称" Binding="{Binding CustomerName}"/>
4 <DataGridTextColumn Header="证件号码" Binding="{Binding CardID}"/>
5 <DataGridTextColumn Header="固定电话" Binding="{Binding Phone}"/>
6 <DataGridTextColumn Header="移动电话" Binding="{Binding MobilePhone}"/>
7 <DataGridTextColumn Header="电子邮件" Binding="{Binding Email}"/>
8 <DataGridTextColumn Header="QQ" Binding="{Binding QQ}"/>
9 <DataGridTextColumn Header="联系地址" Binding="{Binding Address}"/>
10 </DataGrid.Columns>
简单的数据显示可以在sql语句中将字段名另存在(as)中文列名,直接在DataGrid中作为列名使用。
2、自动生成行号(关键是最后一句):
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadDataGrid();
} private void LoadDataGrid()
{
dataGrid1.ItemsSource = UserDAL.GetUserDataSet().Tables[].DefaultView;//读取用户并刷新datagrid
dataGrid1.LoadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
} public void dataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + ;
}
WPF DataGrid 绑定DataSet数据 自动生成行号的更多相关文章
- WPF DataGrid自动生成行号
在使用WPF进行应用程序的开发时,经常会为DataGrid生成行号,这里主要介绍一下生成行号的方法.通常有三种方法,这里主要介绍其中的两种,另一种简单提一下. 1. 直接在LoadingRow事件 ...
- WPF DataGrid 自动生成行号的方法(通过修改RowHeaderTemplate的方式)
WPF中的DataGrid自动生成行号的方法有很多,这里记录了一种通过修改 RowHeaderTemplate的方式来生成行号: 方法一: xaml界面: <Window ... xmlns:l ...
- Dev的GridView中如何自动生成行号
这里提供一个方法,使用简单,只需将GridView传入,即可自动生成行号 public static void SetRowNumberIndicator(GridView gridView) { g ...
- 用ClientDataSet更新数据表,怎样自动生成行号? [问题点数:40分]
ClientDataSet.First;while not ClientDataSet.eof dobegin ClientDataSet.edit; ClientDataSet.FieldByN ...
- WPF DataGrid 绑定数据及时更新的处理
原文:WPF DataGrid 绑定数据及时更新的处理 默认情况下datagrid 绑定数据源后,在界面编辑某一列后,数据不会及时更新到内存对象中.如在同一行上有一个命令对来获取 当前选中行(内存对象 ...
- WPF DataGrid绑定一个组合列
WPF DataGrid绑定一个组合列 前台: <Page.Resources> <local:InfoConverter x:Key="converter& ...
- WPF DataGrid 绑定行双击行命令
WPF DataGrid 绑定行双击行命令 <DataGrid ...> <DataGrid.InputBindings> <MouseBinding MouseActi ...
- WPF DataGrid绑定及列居中
基本的数据绑定 把集合的字段(属性)绑定在DataGrid的Binding属性就能将数据绑定列表 public class CashItem { public int Value { get; set ...
- datagrid 绑定选中数据,列头全选
成品图: xaml代码 <Grid> <DataGrid x:Name="datagrid" Height="Auto" Width=&quo ...
随机推荐
- 转:.NET中使用Redis (二)
原文来自于:http://blog.jobbole.com/83824/ 原文出处: 寒江独钓 欢迎分享原创到伯乐头条 很久以前写了一篇文章 .NET中使用Redis 介绍了如何安装Redis服务 ...
- wlan的QOS配置
WLAN QoS配置 1.1 WLAN QoS简介 802.11网络提供了基于竞争的无线接入服务,但是不同的应用需求对于网络的要求是不同的,而原始的网络不能为不同的应用提供不同质量的接入服务,所以已 ...
- 开源java
http://code.google.com/p/nullpomino/source/checkout http://www.open-open.com/open254058.htm http://w ...
- Knight Tournament
Codeforces Round #207 (Div. 1) A:http://codeforces.com/problemset/problem/356/A 题意:给你n匹马,然后有m场比赛.每场比 ...
- TWinControl.SetBounds与TWinControl.UpdateBounds赏析(定义和调用)
先看它们的函数内容: procedure TControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); begin // 虚函数,TWinCon ...
- 整整68页学习C++的文章
有空看看,有不少好东西: http://dev.21tx.com/language/c/index.shtml
- c#分支语句;循环语句(随堂练习)
1. 输入月份,日期号,输出是今年的第几天 平年,2月28天 switch (变量名) {case "": break} 2. 循环语句: for(int i ...
- windows 10家庭版升级到专业版
因为要搭建一个服务器,需要用到Docker,根据Docker的文档,Docker必须要安装在windows 10 企业版,专业版,或者教育版上.不然不能使用.一直以为要重新下载专业版的镜像重新安装wi ...
- LINUX怎么修改IP地址
1,先搜索了一下,得到以下解释 IP IP地址 Netmark 子网掩码 Gateway 默认网关 HostName 主机名称 DomainName 域名 DNS DNS的IP 2,需要修改的文件常有 ...
- select.poll,epoll的区别与应用
先讲讲同步I/O的五大模型 阻塞式I/O, 非阻塞式I/O, I/O复用,信号驱动I/O(SIGIO),异步I/O模型 而select/poll/epoll属于I/O复用模型 select函数 该函数 ...