Add user control to DataGridViewCell

I am creating a custom control inherited from Windows.System.Forms.Controls.

This is my code for this control:

   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");
        }

    }

I would like to insert this control or several of this control into a DataGridViewCell, but I do not know how to do this.

Thank you in advance for your reply,

Regards,

PS: I'm French, I apologize for any language errors.

+3
source share
1 answer

I would suggest that you use Winforms?

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

From the textbook:

DataGridView , . , , . , , DataGridViewColumn DataGridViewCell. , Control IDataGridViewEditingControl.

+7

Source: https://habr.com/ru/post/1741321/


All Articles