首页 > 代码库 > gridView 练习
gridView 练习
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication40{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { List<per> list = new List<per>(); list.AddRange(new per[] { new per(1, "zwj2", DateTime.Now), new per(2, "zwj3", DateTime.Now), new per(3, "zwj4", DateTime.Now), new per(4, "zwj5", DateTime.Now), new per(5, "zwj6", DateTime.Now) }); gridControl1.DataSource = list; gridView1.IndicatorWidth = 40;// gridView1.Columns[1].AppearanceCell.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center; gridView1.Columns[1].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // 设置标题居中 gridView1.Columns[1].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; gridView1.Columns[0].AppearanceCell.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center; gridView1.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; gridView1.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; gridView1.RowCellStyle += GridView1_RowCellStyle; } private void GridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if (e.Column.FieldName == "times") { e.Column.DisplayFormat.FormatString = "yyyy/MM/dd hh:mm:ss"; } } private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far; if (e.Info.IsRowIndicator) { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1) + ""; } else if (e.RowHandle < 0 && e.RowHandle > -1000) { e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite; e.Info.DisplayText = "G" + e.RowHandle.ToString(); } } } } public class per { public per(int id, string names, DateTime dt) { this.id = id; this.names = names; this.times = dt; } public int id { get; set; } public string names { get; set; } public DateTime times { get; set; } }}
gridView 练习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。