zoukankan      html  css  js  c++  java
  • 一个继承的 DataGridView

    // 允许增加一个 checkbox 列 
    public class DgvBase : DataGridViewX { protected override void OnColumnAdded(DataGridViewColumnEventArgs e) { base.OnColumnAdded(e); //if (e.Column.ValueType == typeof(int) || e.Column.ValueType == typeof(long) || e.Column.ValueType == typeof(float) // || e.Column.ValueType == typeof(double) || e.Column.ValueType == typeof(decimal)) if (e.Column.ValueType == typeof(decimal)) e.Column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { base.OnRowPostPaint(e); //this.Rows[e.RowIndex].Selected ? this.RowHeadersDefaultCellStyle.SelectionForeColor : TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.RowHeadersDefaultCellStyle.Font, new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.RowHeadersWidth - 4, e.RowBounds.Height), this.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right); } protected override void OnCellClick(DataGridViewCellEventArgs e) { base.OnCellClick(e); // 设置此列在点击时可改变值 DataGridViewColumn dc = this.Columns [e.ColumnIndex ]; if (dc.ReadOnly && dc.Name == "IsSelected") this[e.ColumnIndex, e.RowIndex].Value = !Generic.ToBoolean(this[e.ColumnIndex, e.RowIndex].Value); } } public static class DgvExtensions { public static void DataBind(this DgvBase dgv, DataTable dt) { if (dt != null && !dt.Columns.Contains("IsSelected")) { DataColumn dc = dt.Columns.Add("IsSelected", typeof(bool)); dc.SetOrdinal(0); } dgv.DataSource = dt; } }
  • 相关阅读:
    2015年个人记录
    Win10如何新建用户怎么添加新账户
    快速搭建一个本地的FTP服务器
    天气接口
    一张图搞定OAuth2.0
    PHP TS 和 NTS 版本选择
    如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
    Npm vs Yarn 之备忘详单
    浅谈CSRF
    值得看的cookie详解
  • 原文地址:https://www.cnblogs.com/z5337/p/3600022.html
Copyright © 2011-2022 走看看