这里提供一个方法,使用简单,只需将GridView传入,即可自动生成行号
1 public static void SetRowNumberIndicator(GridView gridView)
2 {
3 gridView.BeginUpdate();
4 gridView.OptionsView.ShowIndicator = true;
5 gridView.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(
6 delegate(object sender, RowIndicatorCustomDrawEventArgs e)
7 {
8 if (e.RowHandle >= 0)
9 {
10 int rowNumber = e.RowHandle + 1;
11 e.Info.DisplayText = rowNumber.ToString();
12 }
13 }
14 );
15
16 gridView.DataSourceChanged += new EventHandler(
17 delegate(object sender, EventArgs e)
18 {
19 gridView.IndicatorWidth = 22 + gridView.DataRowCount.ToString().Length * ((int)gridView.Appearance.HeaderPanel.Font.Size);
20 }
21 );
22
23 gridView.EndUpdate();
24 }
效果如下
Dev的GridView中如何自动生成行号,布布扣,bubuko.com
时间: 2024-10-12 17:58:42