自定义控制加入的DataGridViewCell [英] Add Custom Control to DataGridViewCell

查看:164
本文介绍了自定义控制加入的DataGridViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建Windows.System.Forms.Controls继承的自定义控件

I create a custom control inherited from Windows.System.Forms.Controls.

这是我此控件的代码:

   public partial class MonthEventComponent : Control
    {
        private Color couleur;
        private Label labelEvenement;

        public MonthEventComponent(Color couleur_c, String labelEvenement_c )
        {
            InitializeComponent();
            this.couleur = couleur_c;
            this.labelEvenement.Text = labelEvenement_c;
            this.labelEvenement.ForeColor = couleur;
            this.labelEvenement.BackColor = Color.White;
            this.labelEvenement.TextAlign = ContentAlignment.MiddleLeft;
            this.labelEvenement.Dock = DockStyle.Fill;
            this.Controls.Add(labelEvenement);
        }

        public MonthEventComponent()
        {
            InitializeComponent();
            this.couleur = Color.Black;
            this.labelEvenement = new Label();
            this.labelEvenement.ForeColor = couleur;
            this.labelEvenement.BackColor = Color.White;
            this.labelEvenement.Text = "Evénement Initialiser";
            this.labelEvenement.TextAlign = ContentAlignment.MiddleLeft;
            this.labelEvenement.Dock = DockStyle.Fill;

            this.Controls.Add(labelEvenement);

        }


        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            MessageBox.Show("Click");
        }

    }



我想插入这个控制或在DataGridViewCell的这种控制的数倍,但我不知道如何做到这一点。

I would like to insert this control or multiple of this control on a DataGridViewCell but i don't know how to do this.

感谢您提前为你的答案,

Thank you in advance for your answer,

最好的问候,

PS:我是法国人,我对语言错误的任何道歉可以

PS: I'm french, i'm apologize for any can of language errors.

推荐答案

我会假设你正在使用的WinForms?

I would assume you are using Winforms?

这里 ,是如何承载在一个WinForms 的DataGridViewCell 控制上的MSDN教程

Here is an MSDN tutorial on how to host a control in a Winforms DataGridViewCell.

从教程:

DataGridView控件提供了
数列类型,使您的
用户在
各种输入和编辑值的方法。如果这些列类型
不符合您的数据录入的需求,
然而,你可以用细胞创建您自己的
柱类型你选择的主机
控制。要做到这一点,
你必须定义一个派生从的DataGridViewColumn

的DataGridViewCell类。你还必须定义
,从控制和
派生的类实现了
IDataGridViewEditingControl接口。

The DataGridView control provides several column types, enabling your users to enter and edit values in a variety of ways. If these column types do not meet your data-entry needs, however, you can create your own column types with cells that host controls of your choosing. To do this, you must define classes that derive from DataGridViewColumn and DataGridViewCell. You must also define a class that derives from Control and implements the IDataGridViewEditingControl interface.

这篇关于自定义控制加入的DataGridViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆