views:

291

answers:

1

Hello,

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

This is my code of 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 multiple of this control on a DataGridViewCell but i don't know how to do this.

Thank you in advance for your answer,

Best Regards,

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

A: 

I would assume you are using Winforms?

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

From the tutorial:

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.

Zach Johnson
Thank you for your answer, i will see this.
Kovscer