WPF中的DataGrid自动生成行号的方法有很多,这里记录了一种通过修改 RowHeaderTemplate的方式来生成行号: 方法一: xaml界面: <Window ... xmlns:local="clr-namespace:Test" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}"> <Window.Resources> <local:RowT…
  在使用WPF进行应用程序的开发时,经常会为DataGrid生成行号,这里主要介绍一下生成行号的方法.通常有三种方法,这里主要介绍其中的两种,另一种简单提一下. 1. 直接在LoadingRow事件中操作. 这种方式是在code behind文件中操作.即相应的*.xaml.cs文件. 代码如下: this.dataGridSoftware.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.DataGridSoftware_L…
1.绑定数据:dataGrid1.ItemsSource = dataSet.Tables[0].DefaultView; 注意:在创建DataGrid 时可以通过AutoGenerateColumns 属性设置列是否自动生成,从而加入自定义列.如果DataGrid 中同时包含“自动生成列”与“用户自定义列”,则首先创建“用户自定义列”.DataGrid 支持的四种列及其数据类型见下表: DataGrid绑定列名.数据列代码: 1 <DataGrid.Columns> 2 <DataGr…
这里提供一个方法,使用简单,只需将GridView传入,即可自动生成行号 public static void SetRowNumberIndicator(GridView gridView) { gridView.BeginUpdate(); gridView.OptionsView.ShowIndicator = true; gridView.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler( delegate(…
ClientDataSet.First;while not ClientDataSet.eof dobegin  ClientDataSet.edit;  ClientDataSet.FieldByName('行号字段').asInteger := ClientDataSet.RecNo;  ClientDataSet.next;end;…
需求和效果 应用WPF技术进行开发的时候,大多都会遇到给DataGrid添加序号的问题,今天分享一下查阅了很多stackoverflow的文章后,总结和改进过来的方法,先看一下效果图,文末附Demo下载链接 设计思想和代码 这里应用的是单值转换器,获取DataGrid的行号, 转换为序号,思路和实现非常简单,核心代码就几行 public object Convert(object value, Type targetType, object parameter, System.Globaliza…
private function formatIndexNumber(item:Object, colum:Object):String {      return indexNumLabelFun(item, colum.mx_internal::owner);  } public function indexNumLabelFun(value:Object, dataGrid:Object):String {     var arr:Array = (PageDataGrid.dataPro…
<DataGrid Name="tkdg" HorizontalContentAlignment="Center" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" LoadingRow="tkdg_LoadingRow"> ..... private void tkdg_…
<Window x:Class="DataGridExam.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height=&q…
if (mainDataGrid.Items.Count > 0) { var border = VisualTreeHelper.GetChild(mainDataGrid, 0) as Decorator; if (border != null) { var scroll = border.Child as ScrollViewer; if (scroll != null) scroll.ScrollToEnd(); } }…