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 - 蚂蚁 - 安宁
阅读更多
个人分类: Winform
想对作者说点什么? 我来说一句

arcengine 中添加text的代码

2009年10月07日 603B 下载

sharepoint custom webpart

2009年09月14日 41KB 下载

test_picture

2011年09月21日 16KB 下载

没有更多推荐了,返回首页

不良信息举报

DataGridViewCheckColumn 添加 Text

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭