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 ...
随机推荐
- 【MySQL】SQL语法,between and 使用注意事项
业务代码中有条查询学生姓名的sql: select stu_name from stu_info where stu_id between id_1 and id_2; 估计当时一时恍惚,拼接sql时 ...
- js 外部文件加载处理
概述 前端在日常工作中很大一部分时间是在思考页面的优化方案,让页面载入得更快.鉴于javascript是单线程的事件驱动语言,优化工作之一就是:控制图片.swf.iframe等大流量文件以及js和cs ...
- javascript widget ui mvc
MVC只是javascript的一个UI模式 JavaScript UI----UI, Template, MVC(View)----Backbone, Angular RequireJS------ ...
- Ajax页面逻辑
逻辑上模拟整个与服务器通信的过程.在没有真正与服务器通信的时候,如何写这样的ajax请求. 先根据页面结构创建一个静态数据(JSON) var arrival_address_data={" ...
- Strust2的json插件
以下这段摘自网上: Json是一种轻量级的数据交换格式,JSon插件提供了一种名为json的ActionResultType .一旦为Action指定了该结果处理类型,JSON插件就会自动将Actio ...
- Oracle索引扫描算法
SQL> create table t as select * from dba_objects; Table created. SQL> create index idx_t on t( ...
- 【HDOJ】2451 Simple Addition Expression
递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...
- poj3186 Treats for the Cows
http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total S ...
- LeetCode (85): Maximal Rectangle [含84题分析]
链接: https://leetcode.com/problems/maximal-rectangle/ [描述] Given a 2D binary matrix filled with '0's ...
- 菜鸟学习SSH(一)——Struts实现简单登录(附源码)
从今天开始,一起跟各位聊聊java的三大框架——SSH.先从Struts开始说起,Struts对MVC进行了很好的封装,使用Struts的目的是为了帮助我们减少在运用MVC设计模型来开发Web应用的时 ...