gridView 练习

Posted 刀的剑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 练习的主要内容,如果未能解决你的问题,请参考以下文章

GridView - 片段 - LongClick

片段中的网格视图

滚动包含 x 个 GridView 的整个片段

如何在Android中加载带有动画的cardview GridView?

在片段内使用 GridView 时应用程序崩溃

如何在选项卡片段内调用gridView适配器