views:

13

answers:

0

Hello,

I have creating a custom datagridviewcell where i have implementing the editing control mode to show a custom control.

this is my code :

public class MonthCalendarCell : DataGridViewImageCell
{

    public DateTime date { get; set; }
    public MonthPanelEvent panelEvent { get; set; }

    public MonthCalendarCell() : base()
    {
        this.date = new DateTime();
        this.date = DateTime.Today;
        this.panelEvent = new MonthPanelEvent();
        Padding newPadding = new Padding(0);
        this.ImageLayout = DataGridViewImageCellLayout.NotSet;
        this.Style.Padding = newPadding;
    }        

    public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        base.InitializeEditingControl(rowIndex, initialFormattedValue,
            dataGridViewCellStyle);
        this.ReadOnly = false;
        MonthPanelEvent ctl = DataGridView.EditingControl as MonthPanelEvent;
        ctl.affichageMois = this.panelEvent.affichageMois;
        ctl.date.Text = this.panelEvent.date.Text;
        ctl.listAppointment = panelEvent.listAppointment;
        ctl.loadAppoinment();
    }

    public override Type EditType
    {
        get
        {
            // Return the type of the editing contol that CalendarCell uses.
            return typeof(MonthPanelEvent);
        }
    }

    public override Type ValueType
    {
        get
        {
            // Return the type of the value that CalendarCell contains.
            return typeof(Image);
        }
    }


    public override object DefaultNewRowValue
    {
        get
        {
            // Use the current date and time as the default value.
            return Image.FromFile("C:\\blank.jpg");
        }
    }

    protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
    {
        if (base.DataGridView != null)
        {
            Point point1 = base.DataGridView.CurrentCellAddress;
            if (((point1.X == e.ColumnIndex) && (point1.Y == e.RowIndex)) && (e.Button == MouseButtons.Left))
            {
                if (base.DataGridView.EditMode != DataGridViewEditMode.EditProgrammatically)
                {
                    base.DataGridView.BeginEdit(true);
                }
            }
        }
    }

But i'm facing a problem, indeed i would like to know if its possible to block all the cell on this editing control mode ? Because for the moment, i create a bitmap of this control when it's not on editing control mode, it's take a lot of memory.

Thank you in advance for your help,

Best regards.

Ps: Sorry for my english ^^.