如题,这个要怎么增加按钮列呢?

解决方案 »

  1.   

    是增加行还是增加列?
    如果是增加行
    那你可以在绑定的表中做
    Tb.DefaultView.AllowNew=AllowAdd;//是否可自动增加行
      

  2.   

    public delegate void DataViewButtonClickHandle(object sender, DataViewEventArgs args);
    /// <summary>
    /// DataViewButtonColumn 的摘要说明。
    /// </summary>
    public class DataViewButtonColumn : DataViewColumn
    {
    public event DataViewButtonClickHandle DataViewButtonClick;
    private int curRow;
    private object component = null; public DataViewButtonColumn(int column) : base(column)
    {
    this.Control = new Button();
    this.Button.Text = "\u2026";
    this.Button.FlatStyle = FlatStyle.System;
    this.Button.Width = 20;
    this.Button.Click += new EventHandler(this.FireButtonClick);
    } public Button Button
    {
    get
    {
    return this.Control as Button;
    }
    }  public override Control Control
    {
    set
    {
    if(value is Button)
    base.Control = value;
    }
    } protected override bool Commit(CurrencyManager DataSource, int RowNum)
    {
    this.HideControl();
    if (this.inEdit)
    {
    try
    {
    if (!this.DataGridTableStyle.DataGrid.ReadOnly && component != null)
    {
    this.SetColumnValueAtRow(DataSource, RowNum, component);
    }
    }
    catch (Exception err)
    {
    throw err;
    }
    finally
    {
    this.EndEdit();
    }
    }
    return true;
    }  protected override void Edit(CurrencyManager Source, int Rownum, Rectangle Bounds, bool ReadOnly, string InstantText, bool CellIsVisible)
    {
    if(this.DataGridTableStyle.DataGrid.ReadOnly || this.ReadOnly)
    return;
    base.Edit(Source, Rownum, Bounds, ReadOnly, InstantText, CellIsVisible);
    curRow = Rownum;
    this.Control.Enabled = CellIsVisible;
    this.Control.Visible = true;
    this.Control.Height = Bounds.Height;
    this.Control.Top = Bounds.Top;
    this.Control.Left = Bounds.Left + (Bounds.Width - this.Control.Width);
    if (this.Control.Visible)
    this.DataGridTableStyle.DataGrid.Invalidate(Bounds);
    this.inEdit = true;
    } protected override int GetMinimumHeight()
    {
    return 20;
    }  private void FireButtonClick(object sender, EventArgs e)
    {
    if (this.DataViewButtonClick != null)
    this.DataViewButtonClick(sender, new DataViewEventArgs(this, curRow));
    }
    }
    看看哈
      

  3.   

    DataViewColumn 这个是从 DataGridColumnStyle 继承的
      

  4.   

    哇 看上去是挺麻烦的~~ 呵呵  谢谢pretty_soft()