1

私はデータグリッドビューにユーザーコントロールを追加したいのですが、私のユーザーコントロールはとてもシンプルです:

public partial class UpDownControl : UserControl
{
    public event EventHandler UpClick;
    public event EventHandler DownClick;

    public UpDownControl(string id)
    {
        InitializeComponent();
        this.Tag = id;
    }

    void BDownClick(object sender, EventArgs e)
    {
        if(DownClick!=null)
            DownClick(this,e);
    }

    void BUpClick(object sender, EventArgs e)
    {
        if(UpClick!=null)
            UpClick(this,e);
    }
}

私がしたいのは、このコントロールを datagridview の最初の列に追加することだけです。自分で解決策を見つけようとしましたが、無駄に見つかりませんでした。このリンクhttp://msdn.microsoft.com/en-us/library/7tas5c80.aspxを見に行くように言わないで ください、私はそれをすべて読みましたが、私のユーザーコントロールでそれを行う方法が見つかりませんでした。

だから、これは私の現在のコードです:

for(int i=0;i<lposte.Count;++i)
{
    UpDownControl updown = new UpDownControl("test1");
    updown.DownClick += new EventHandler(testvincdown);
    updown.UpClick += new EventHandler(testvincup);

    rang = 1;
    CustomColumn col = new CustomColumn();
    CustomeCell cell = new CustomeCell();

    col.CellTemplate = cell;

    dataGridView1.Columns.Add(col);
    dataGridView1.Rows.add(updown);
}

public class CustomColumn : DataGridViewColumn 
{
    public CustomColumn() : base(new CustomeCell()) { }
    public override DataGridViewCell CellTemplate
    {
        get
        {
            return base.CellTemplate;
        }
        set
        {
            // Ensure that the cell used for the template is a CalendarCell.
            if (value != null &&
                !value.GetType().IsAssignableFrom(typeof(CustomeCell)))
            {
                throw new InvalidCastException("It should be a custom Cell");
            }
            base.CellTemplate = value;
        }
    }
}
public class CustomeCell : DataGridViewCell
{
    public CustomeCell() : base() { }
    public override Type ValueType
    {
        get
        {
            return typeof(UpDownControl);
        }
    }
} 

どんな助けでも大歓迎です。PS: 私の英語が完璧でない場合は申し訳ありませんが、最善を尽くしました。

ありがとうございました。

ヴィンク

4

0 に答える 0