DataGridViewCheckColumn 添加 Text

 public class DataGridViewCheckAndTextColumn : DataGridViewCheckBoxColumn
    {
       public DataGridViewCheckAndTextColumn()
       {
           this.CellTemplate = new DataGridViewCheckAndTextCell();
       }

    }

------------------------------------------------------------------------------------------------------------------------------------

 public  class DataGridViewCheckAndTextCell : DataGridViewCheckBoxCell

    {
        public DataGridViewCheckAndTextCell()
        {
            this.Enabled = true;
        }

        private bool enabled;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
                this.ReadOnly = !enabled;
            }
        }

        private string text;
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        private System.Drawing.Color color;
        public System.Drawing.Color Color
        {
            get
            {
                return color;
            }
            set { color = value; }
        }

        private System.Drawing.Font font;
        public System.Drawing.Font Font
        {
            get { return font; }
            set { font = value; }
        }

        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
                      int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue,
                      string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value,
                formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            if (this.Font == null)
                this.Font = cellStyle.Font;

            if (!this.Enabled)
                this.Color = Color.Gray;
            else if (this.Color.IsEmpty)
                this.Color = cellStyle.ForeColor;
 
            Rectangle contentBounds = this.GetContentBounds(rowIndex);

            SizeF ForeSize = graphics.MeasureString(this.Text, this.Font);

            Point stringLocation = new Point();
            stringLocation.Y = cellBounds.Y + 4;

            if (contentBounds.Right + 2 + ForeSize.Width > cellBounds.Width)
            {
                stringLocation.X = cellBounds.X + contentBounds.Right + 2;
            }
            else
            {
                stringLocation.X = cellBounds.X + cellBounds.Width - (int)ForeSize.Width  - 4;
            }
      
            graphics.DrawString(this.Text, this.Font, new SolidBrush(this.Color), stringLocation);
        }

    }

----------------------------------------------------------------------------------------------------------------------

    DataGridViewCheckAndTextColumn NewJuryoColumn = new DataGridViewCheckAndTextColumn();
            NewJuryoColumn.Name = "zhongliang" ;
            NewJuryoColumn.HeaderText = 新重量;
            NewJuryoColumn.Width = 100;
            NewJuryoColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
            NewJuryoColumn.DefaultCellStyle.Font = new System.Drawing.Font("MS 明朝", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));          

           NewJuryoColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            DGVform.Columns.Add(NewJuryoColumn);

---------------------------------------------------------------------------------------------------------------------------------

 

            dataGridView1.Rows.Add();
            index = dataGridView1.Rows.Count - 1;
              dr = dataGridView1.Rows[index];           

            DataGridViewCheckAndTextCell ctCell = dr.Cells["zhongliang"] as DataGridViewCheckAndTextCell;
            ctCell.Enabled = true;
            ctCell.Text = "500";

  ctCell.Value = false;

DataGridViewCheckColumn  添加 Text - 蚂蚁 - 安宁
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值