vs.net2003中得datagrid可以通过dataGridTableStyle增加自定义label控件

DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)dg1.TableStyles[0].GridColumnStyles[2];
System.Windows.Forms.Label btn = new System.Windows.Forms.Label();
btn.BackColor = System.Drawing.SystemColors.Window;
btn.Cursor = System.Windows.Forms.Cursors.Hand;
btn.Image = ((System.Drawing.Image)(resources.GetObject("btnAdd.Image")));
btn.Text = "删除此类型";
btn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
btn.Click +=new EventHandler(btn_Click);
dgtb.TextBox.Controls.Add(btn);在vs.net2005中使用了控件datagridview.里面有DataGridViewTextBoxCell  以及众多类型得列可以设置。但我现在还想增加一个我定义得label列。可是没有了Controls.Add.怎么加入label列~~。求助啊~~~期盼有人弄过给个提示

解决方案 »

  1.   

    你可以从DataGridViewTextBoxColumn 先继承一个自己的column
    再这个类里重写CellTemplate
    public override DataGridViewCell CellTemplate
    {
    get
    {
    return base.CellTemplate;
    }
    set
    {
    if (value == null || value is yourDataGridViewtextboxCell)
    {
    base.CellTemplate = value;
    }
    else
    {
                        throw new Exception("Must be a yourDataGridViewtextboxCell");
    }
    }
    }
    然后再继承DataGridViewTextboxCell
      

  2.   

    public override object Clone()
    {
    yourDataGridViewTextBoxCell cell = base.Clone() as yourDataGridViewTextBoxCell ;
    cell.m_refValue = this.m_refValue;
    cell.m_expression = this.m_expression;
    cell.m_editinDisplayMember = this.m_editinDisplayMember;//这些是我自己定义的属性,要在这重写这个方法里 (cell as yourDataGridViewTextBoxCell ).DataSource = base.DataSource;
    (cell as yourDataGridViewTextBoxCell ).ValueMember = base.ValueMember;
    (cell as yourDataGridViewTextBoxCell ).DisplayMember = base.DisplayMember; return cell;
    }
      

  3.   

    刚下VS2005,可惜磁盘只剩下30M空间,郁闷中。
    我也想用2005阿。。
      

  4.   

    郁闷啊又发现datagridview head的颜色不能变。listview也是