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; }

    }

}

 

posted @ 2016-10-07 09:50  刀小爱  阅读(147)  评论(0编辑  收藏  举报